ZQuest Classic Coverage Report


Directory: src/
File: src/zc/script_drawing.cpp
Date: 2025-05-10 03:10:39
Exec Total Coverage
Lines: 1435 5728 25.1%
Functions: 53 108 49.1%
Branches: 608 2911 20.9%

Line Branch Exec Source
1 //! ritate_sprite_trans doesn't seem to be supported by or allegro header !?
2
3 //glibc 2.28 and later require this: -Z
4 #include <optional>
5 #include <utility>
6 #ifdef __GNUG__
7 #define ALLEGRO_NO_FIX_ALIASES
8 #endif
9
10 #include "base/qrs.h"
11 #include "base/dmap.h"
12 #include "base/zdefs.h"
13 #include "base/zc_alleg.h"
14 #include "zc/script_drawing.h"
15 #include "zc/rendertarget.h"
16 #include "zc/maps.h"
17 #include "tiles.h"
18 #include "zc/zelda.h"
19 #include "zc/ffscript.h"
20 #include "base/util.h"
21 #include "subscr.h"
22 #include "drawing.h"
23 #include "base/mapscr.h"
24 #include "base/misctypes.h"
25 using namespace util;
26 extern refInfo *ri;
27 extern script_bitmaps scb;
28 #include <stdio.h>
29 #include <fstream>
30
31 #define DegtoFix(d) ((d)*0.7111111111111)
32 #define RadtoFix(d) ((d)*40.743665431525)
33
34 static int32_t secondary_draw_origin_xoff;
35 static int32_t secondary_draw_origin_yoff;
36
37 100340850 static std::optional<std::pair<int, int>> get_draw_origin_offset(DrawOrigin draw_origin, int draw_origin_target_uid, int xoff, int yoff)
38 {
39 int xoffset;
40 int yoffset;
41
2/2
✓ Branch 0 taken 40476 times.
✓ Branch 1 taken 100300374 times.
100340850 if (draw_origin == DrawOrigin::Region)
42 {
43 40476 xoffset = xoff - viewport.x;
44 40476 yoffset = yoff - viewport.y;
45 40476 }
46
2/2
✓ Branch 0 taken 8072 times.
✓ Branch 1 taken 100292302 times.
100300374 else if (draw_origin == DrawOrigin::RegionScrollingNew)
47 {
48 8072 xoffset = xoff + FFCore.ScrollingData[SCROLLDATA_NRX];
49 8072 yoffset = yoff + FFCore.ScrollingData[SCROLLDATA_NRY];
50 8072 }
51
2/2
✓ Branch 0 taken 93849827 times.
✓ Branch 1 taken 6442475 times.
100292302 else if (draw_origin == DrawOrigin::PlayingField)
52 {
53 93849827 xoffset = xoff;
54 93849827 yoffset = yoff;
55 93849827 }
56
2/2
✓ Branch 0 taken 6437165 times.
✓ Branch 1 taken 5310 times.
6442475 else if (draw_origin == DrawOrigin::Screen)
57 {
58 6437165 xoffset = 0;
59 6437165 yoffset = 0;
60 6437165 }
61
1/2
✓ Branch 0 taken 5310 times.
✗ Branch 1 not taken.
5310 else if (draw_origin == DrawOrigin::Sprite)
62 {
63 5310 sprite* draw_origin_target = sprite::getByUID(draw_origin_target_uid);
64
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5310 times.
5310 if (!draw_origin_target)
65 {
66 Z_scripterrlog("Warning: Ignoring draw command using DRAW_ORIGIN_SPRITE with non-existent sprite uid: %d.\n", draw_origin_target_uid);
67 return std::nullopt;
68 }
69
70 5310 xoffset = xoff - viewport.x + draw_origin_target->x.getInt();
71 5310 yoffset = yoff - viewport.y + draw_origin_target->y.getInt();
72 5310 }
73 else
74 {
75 // Unexpected.
76 xoffset = 0;
77 yoffset = 0;
78 }
79
80 100340850 return std::make_pair(xoffset, yoffset);
81 100340850 }
82
83 380638 std::pair<int, bool> resolveScriptingBitmapId(int scripting_bitmap_id)
84 {
85
2/2
✓ Branch 0 taken 287649 times.
✓ Branch 1 taken 92989 times.
380638 if (scripting_bitmap_id < 0)
86 {
87 // Handles zscript values for RT_SCREEN, etc.
88 92989 return {scripting_bitmap_id / 10000, false};
89 }
90
3/4
✓ Branch 0 taken 287649 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 660 times.
✓ Branch 3 taken 286989 times.
287649 else if (scripting_bitmap_id - 10 >= -2 && scripting_bitmap_id - 10 <= rtBMP6)
91 {
92 // Handles Game->LoadBitmapID, which sets the bitmap pointer as a "long" int.
93 660 return {scripting_bitmap_id - 10, false};
94 }
95 else
96 {
97 // This is a user bitmap.
98 286989 return {scripting_bitmap_id, true};
99 }
100 380638 }
101
102 inline double sd_log2( double n )
103 {
104 // log(n)/log(2) is log2.
105 double v = log( (double)n ) / log( (double)2 );
106 return v;
107 }
108
109 inline bool isPowerOfTwo(int32_t n)
110 {
111 if(n==0)
112 return false;
113
114 return (ceil(sd_log2(n)) == floor(sd_log2(n)));
115 }
116
117
118
119 template<class T> inline
120 241988 fixed degrees_to_fixed(T d)
121 {
122 241988 return ftofix(DegtoFix(d));
123 }
124 template<class T> inline
125 fixed radians_to_fixed(T d)
126 {
127 return ftofix(RadtoFix(d));
128 }
129
130 BITMAP* ScriptDrawingBitmapPool::_parent_bmp = 0;
131
132 class TileHelper
133 {
134 public:
135
136 46094 static void OldPutTile(BITMAP* _Dest, int32_t tile, int32_t x, int32_t y, int32_t w, int32_t h, int32_t color, int32_t flip, byte skiprows=0)
137 {
138 // Past the end of the tile page?
139
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 46094 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
46094 if(skiprows>0 && tile%TILES_PER_ROW+w>=TILES_PER_ROW)
140 {
141 byte w2=(tile+w)%TILES_PER_ROW;
142 OldPutTile(_Dest, tile, x, y, w-w2, h, color, flip);
143 OldPutTile(_Dest, tile+(w-w2)+(skiprows*TILES_PER_ROW), x+16*(w-w2), y, w2, h, color, flip);
144 return;
145 }
146
147
1/5
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 46094 times.
46094 switch(flip)
148 {
149 case 1:
150 for(int32_t j=0; j<h; j++)
151 for(int32_t k=w-1; k>=0; k--)
152 oldputtile16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+j*16, color, flip);
153
154 break;
155
156 case 2:
157 for(int32_t j=h-1; j>=0; j--)
158 for(int32_t k=0; k<w; k++)
159 oldputtile16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+((h-1)-j)*16, color, flip);
160
161 break;
162
163 case 3:
164 for(int32_t j=h-1; j>=0; j--)
165 for(int32_t k=w-1; k>=0; k--)
166 oldputtile16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+((h-1)-j)*16, color, flip);
167
168 break;
169
170 46094 case 0:
171 default:
172
2/2
✓ Branch 0 taken 181240 times.
✓ Branch 1 taken 46094 times.
227334 for(int32_t j=0; j<h; j++)
173
2/2
✓ Branch 0 taken 1111148 times.
✓ Branch 1 taken 181240 times.
1292388 for(int32_t k=0; k<w; k++)
174 1292388 oldputtile16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+j*16, color, flip);
175
176 46094 break;
177 }
178 46094 }
179
180 3973615 static void OverTile(BITMAP* _Dest, int32_t tile, int32_t x, int32_t y, int32_t w, int32_t h, int32_t color, int32_t flip, byte skiprows=0)
181 {
182 3973615 overtileblock16(_Dest,tile,x,y,w,h,color,flip,skiprows);
183 3973615 }
184
185 static void OverTileCloaked(BITMAP* _Dest, int32_t tile, int32_t x, int32_t y, int32_t w, int32_t h, int32_t flip, byte skiprows=0)
186 {
187 if(skiprows>0 && tile%TILES_PER_ROW+w>=TILES_PER_ROW)
188 {
189 byte w2=(tile+w)%TILES_PER_ROW;
190 OverTileCloaked(_Dest, tile, x, y, w-w2, h, flip);
191 OverTileCloaked(_Dest, tile+(w-w2)+(skiprows*TILES_PER_ROW), x+16*(w-w2), y, w2, h, flip);
192 return;
193 }
194
195 switch(flip)
196 {
197 case 1:
198 for(int32_t j=0; j<h; j++)
199 for(int32_t k=w-1; k>=0; k--)
200 overtilecloaked16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+j*16, flip);
201
202 break;
203
204 case 2:
205 for(int32_t j=h-1; j>=0; j--)
206 for(int32_t k=0; k<w; k++)
207 overtilecloaked16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+((h-1)-j)*16, flip);
208
209 break;
210
211 case 3:
212 for(int32_t j=h-1; j>=0; j--)
213 for(int32_t k=w-1; k>=0; k--)
214 overtilecloaked16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+((h-1)-j)*16, flip);
215
216 break;
217
218 default:
219 for(int32_t j=0; j<h; j++)
220 for(int32_t k=0; k<w; k++)
221 overtilecloaked16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+j*16, flip);
222
223 break;
224 }
225 }
226
227 288307 static void OverTileTranslucent(BITMAP* _Dest, int32_t tile, int32_t x, int32_t y, int32_t w, int32_t h, int32_t color, int32_t flip, int32_t opacity, byte skiprows=0)
228 {
229
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 288307 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
288307 if(skiprows>0 && tile%TILES_PER_ROW+w>=TILES_PER_ROW)
230 {
231 byte w2=(tile+w)%TILES_PER_ROW;
232 OverTileTranslucent(_Dest, tile, x, y, w-w2, h, color, flip, opacity);
233 OverTileTranslucent(_Dest, tile+(w-w2)+(skiprows*TILES_PER_ROW), x+16*(w-w2), y, w2, h, color, flip, opacity);
234 return;
235 }
236
237
1/4
✓ Branch 0 taken 288307 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
288307 switch(flip)
238 {
239 case 1:
240 for(int32_t j=0; j<h; j++)
241 for(int32_t k=w-1; k>=0; k--)
242 overtiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+j*16, color, flip, opacity);
243
244 break;
245
246 case 2:
247 for(int32_t j=h-1; j>=0; j--)
248 for(int32_t k=0; k<w; k++)
249 overtiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+((h-1)-j)*16, color, flip, opacity);
250
251 break;
252
253 case 3:
254 for(int32_t j=h-1; j>=0; j--)
255 for(int32_t k=w-1; k>=0; k--)
256 overtiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+((h-1)-j)*16, color, flip, opacity);
257
258 break;
259
260 default:
261
2/2
✓ Branch 0 taken 1671585 times.
✓ Branch 1 taken 288307 times.
1959892 for(int32_t j=0; j<h; j++)
262
2/2
✓ Branch 0 taken 23550646 times.
✓ Branch 1 taken 1671585 times.
25222231 for(int32_t k=0; k<w; k++)
263 25222231 overtiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+j*16, color, flip, opacity);
264
265 288307 break;
266 }
267 288307 }
268
269 static void PutTileTranslucent(BITMAP* _Dest, int32_t tile, int32_t x, int32_t y, int32_t w, int32_t h, int32_t color, int32_t flip, int32_t opacity, byte skiprows=0)
270 {
271 if(skiprows>0 && tile%TILES_PER_ROW+w>=TILES_PER_ROW)
272 {
273 byte w2=(tile+w)%TILES_PER_ROW;
274 PutTileTranslucent(_Dest, tile, x, y, w-w2, h, color, flip, opacity);
275 PutTileTranslucent(_Dest, tile+(w-w2)+(skiprows*TILES_PER_ROW), x+16*(w-w2), y, w2, h, color, flip, opacity);
276 return;
277 }
278
279 switch(flip)
280 {
281 case 1:
282 for(int32_t j=0; j<h; j++)
283 for(int32_t k=w-1; k>=0; k--)
284 puttiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+j*16, color, flip, opacity);
285
286 break;
287
288 case 2:
289 for(int32_t j=h-1; j>=0; j--)
290 for(int32_t k=0; k<w; k++)
291 puttiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+((h-1)-j)*16, color, flip, opacity);
292
293 break;
294
295 case 3:
296 for(int32_t j=h-1; j>=0; j--)
297 for(int32_t k=w-1; k>=0; k--)
298 puttiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+((h-1)-j)*16, color, flip, opacity);
299
300 break;
301
302 default:
303 for(int32_t j=0; j<h; j++)
304 for(int32_t k=0; k<w; k++)
305 puttiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+j*16, color, flip, opacity);
306
307 break;
308 }
309 }
310 };
311
312
313
314
315 2487966 void do_rectr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
316 {
317 //sdci[1]=layer
318 //sdci[2]=x
319 //sdci[3]=y
320 //sdci[4]=x2
321 //sdci[5]=y2
322 //sdci[6]=color
323 //sdci[7]=scale factor
324 //sdci[8]=rotation anchor x
325 //sdci[9]=rotation anchor y
326 //sdci[10]=rotation angle
327 //sdci[11]=fill
328 //sdci[12]=opacity
329
1/2
✓ Branch 0 taken 2487966 times.
✗ Branch 1 not taken.
2487966 if(sdci[7]==0) //scale
330 {
331 return;
332 }
333
334 2487966 int32_t x1=sdci[2]/10000;
335 2487966 int32_t y1=sdci[3]/10000;
336 2487966 int32_t x2=sdci[4]/10000;
337 2487966 int32_t y2=sdci[5]/10000;
338
339
1/2
✓ Branch 0 taken 2487966 times.
✗ Branch 1 not taken.
2487966 if(x1>x2)
340 {
341 zc_swap(x1,x2);
342 }
343
344
2/2
✓ Branch 0 taken 2468450 times.
✓ Branch 1 taken 19516 times.
2487966 if(y1>y2)
345 {
346 19516 zc_swap(y1,y2);
347 19516 }
348
349
2/2
✓ Branch 0 taken 2486242 times.
✓ Branch 1 taken 1724 times.
2487966 if(sdci[7] != 10000)
350 {
351 1724 int32_t w=x2-x1+1;
352 1724 int32_t h=y2-y1+1;
353 1724 int32_t w2=(w*sdci[7])/10000;
354 1724 int32_t h2=(h*sdci[7])/10000;
355 1724 x1=x1-((w2-w)/2);
356 1724 x2=x2+((w2-w)/2);
357 1724 y1=y1-((h2-h)/2);
358 1724 y2=y2+((h2-h)/2);
359 1724 }
360
361 2487966 int32_t color=sdci[6]/10000;
362
363
2/2
✓ Branch 0 taken 2451487 times.
✓ Branch 1 taken 36479 times.
2487966 if(sdci[12]/10000<=127) //translucent
364 {
365 36479 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
366 36479 }
367
368
2/2
✓ Branch 0 taken 82060 times.
✓ Branch 1 taken 2405906 times.
2487966 if(sdci[10]==0) //no rotation
369 {
370
2/2
✓ Branch 0 taken 833324 times.
✓ Branch 1 taken 1572582 times.
2405906 if(sdci[11]) //filled
371 {
372 1572582 rectfill(bmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
373 1572582 }
374 else //outline
375 {
376 833324 rect(bmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
377 }
378 2405906 }
379 else //rotate
380 {
381 int32_t xy[16];
382 82060 int32_t rx=sdci[8]/10000;
383 82060 int32_t ry=sdci[9]/10000;
384 82060 fixed ra1=itofix(sdci[10]%10000)/10000;
385 82060 fixed ra2=itofix(sdci[10]/10000);
386 82060 fixed ra=ra1+ra2;
387 82060 ra = (ra/360)*256;
388
389 82060 fixed fcosa = fixcos(ra);
390 82060 fixed fsina = fixsin(ra);
391
392 82060 xy[ 0]=xoffset+rx + fixtoi((fcosa * (x1 - rx) - fsina * (y1 - ry))); //x1
393 82060 xy[ 1]=yoffset+ry + fixtoi((fsina * (x1 - rx) + fcosa * (y1 - ry))); //y1
394 82060 xy[ 2]=xoffset+rx + fixtoi((fcosa * (x2 - rx) - fsina * (y1 - ry))); //x2
395 82060 xy[ 3]=yoffset+ry + fixtoi((fsina * (x2 - rx) + fcosa * (y1 - ry))); //y1
396 82060 xy[ 4]=xoffset+rx + fixtoi((fcosa * (x2 - rx) - fsina * (y2 - ry))); //x2
397 82060 xy[ 5]=yoffset+ry + fixtoi((fsina * (x2 - rx) + fcosa * (y2 - ry))); //y2
398 82060 xy[ 6]=xoffset+rx + fixtoi((fcosa * (x1 - rx) - fsina * (y2 - ry))); //x1
399 82060 xy[ 7]=yoffset+ry + fixtoi((fsina * (x1 - rx) + fcosa * (y2 - ry))); //y2
400 82060 xy[ 8]=xoffset+rx + fixtoi((fcosa * (x1 - rx) - fsina * (y1 - ry + 1))); //x1
401 82060 xy[ 9]=yoffset+ry + fixtoi((fsina * (x1 - rx) + fcosa * (y1 - ry + 1))); //y1
402 82060 xy[10]=xoffset+rx + fixtoi((fcosa * (x2 - rx - 1) - fsina * (y1 - ry))); //x2
403 82060 xy[11]=yoffset+ry + fixtoi((fsina * (x2 - rx - 1) + fcosa * (y1 - ry))); //y1
404 82060 xy[12]=xoffset+rx + fixtoi((fcosa * (x2 - rx) - fsina * (y2 - ry - 1))); //x2
405 82060 xy[13]=yoffset+ry + fixtoi((fsina * (x2 - rx) + fcosa * (y2 - ry - 1))); //y2
406 82060 xy[14]=xoffset+rx + fixtoi((fcosa * (x1 - rx + 1) - fsina * (y2 - ry))); //x1
407 82060 xy[15]=yoffset+ry + fixtoi((fsina * (x1 - rx + 1) + fcosa * (y2 - ry))); //y2
408
409
1/2
✓ Branch 0 taken 82060 times.
✗ Branch 1 not taken.
82060 if(sdci[11]) //filled
410 {
411 82060 polygon(bmp, 4, xy, color);
412 82060 }
413 else //outline
414 {
415 line(bmp, xy[0], xy[1], xy[10], xy[11], color);
416 line(bmp, xy[2], xy[3], xy[12], xy[13], color);
417 line(bmp, xy[4], xy[5], xy[14], xy[15], color);
418 line(bmp, xy[6], xy[7], xy[ 8], xy[ 9], color);
419 }
420 }
421
422 2487966 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
423 2487966 }
424
425 void do_framer(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
426 {
427 //sdci[1]=layer
428 //sdci[2]=x
429 //sdci[3]=y
430 //sdci[4]=tile
431 //sdci[5]=cset
432 //sdci[6]=width
433 //sdci[7]=height
434 //sdci[8]=overlay
435 //sdci[9]=opacity
436
437 int32_t x=sdci[2]/10000;
438 int32_t y=sdci[3]/10000;
439
440 int32_t tile=sdci[4]/10000;
441 int32_t cs=sdci[5]/10000;
442 int32_t w=sdci[6]/10000;
443 int32_t h=sdci[7]/10000;
444 bool overlay=sdci[8];
445 bool trans=(sdci[9]/10000<=127);
446
447 frame2x2(bmp, x + xoffset, y + yoffset, tile, cs, w, h, 0, overlay, trans);
448 }
449
450
451
452 1160036 void do_circler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
453 {
454 //sdci[1]=layer
455 //sdci[2]=x
456 //sdci[3]=y
457 //sdci[4]=radius
458 //sdci[5]=color
459 //sdci[6]=scale factor
460 //sdci[7]=rotation anchor x
461 //sdci[8]=rotation anchor y
462 //sdci[9]=rotation angle
463 //sdci[10]=fill
464 //sdci[11]=opacity
465
1/2
✓ Branch 0 taken 1160036 times.
✗ Branch 1 not taken.
1160036 if(sdci[6]==0) //scale
466 {
467 return;
468 }
469
470 1160036 int32_t x1=sdci[2]/10000;
471 1160036 int32_t y1=sdci[3]/10000;
472 1160036 qword r=sdci[4];
473
474
1/2
✓ Branch 0 taken 1160036 times.
✗ Branch 1 not taken.
1160036 if(sdci[6] != 10000)
475 {
476 r*=sdci[6];
477 r/=10000;
478 }
479
480 1160036 r/=10000;
481 1160036 int32_t color=sdci[5]/10000;
482
483
2/2
✓ Branch 0 taken 989014 times.
✓ Branch 1 taken 171022 times.
1160036 if(sdci[11]/10000<=127) //translucent
484 {
485 171022 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
486 171022 }
487
488
5/6
✓ Branch 0 taken 58575 times.
✓ Branch 1 taken 1101461 times.
✓ Branch 2 taken 1344 times.
✓ Branch 3 taken 57231 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1344 times.
1160036 if(sdci[9]!=0&&(sdci[2]!=sdci[7]||sdci[3]!=sdci[8])) //rotation
489 {
490 int32_t xy[2];
491 57231 int32_t rx=sdci[7]/10000;
492 57231 int32_t ry=sdci[8]/10000;
493 57231 fixed ra1=itofix(sdci[9]%10000)/10000;
494 57231 fixed ra2=itofix(sdci[9]/10000);
495 57231 fixed ra=ra1+ra2;
496 57231 ra = (ra/360)*256;
497
498 57231 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
499 57231 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
500 57231 x1=xy[0];
501 57231 y1=xy[1];
502 57231 }
503
504
2/2
✓ Branch 0 taken 1143022 times.
✓ Branch 1 taken 17014 times.
1160036 if(sdci[10]) //filled
505 {
506 1143022 circlefill(bmp, x1+xoffset, y1+yoffset, r, color);
507 1143022 }
508 else //outline
509 {
510 17014 circle(bmp, x1+xoffset, y1+yoffset, r, color);
511 }
512
513 1160036 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
514 1160036 }
515
516
517 void do_arcr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
518 {
519 //sdci[1]=layer
520 //sdci[2]=x
521 //sdci[3]=y
522 //sdci[4]=radius
523 //sdci[5]=start angle
524 //sdci[6]=end angle
525 //sdci[7]=color
526 //sdci[8]=scale factor
527 //sdci[9]=rotation anchor x
528 //sdci[10]=rotation anchor y
529 //sdci[11]=rotation angle
530 //sdci[12]=closed
531 //sdci[13]=fill
532 //sdci[14]=opacity
533
534 if(sdci[8]==0) //scale
535 {
536 return;
537 }
538
539 int32_t cx=sdci[2]/10000;
540 int32_t cy=sdci[3]/10000;
541 qword r=sdci[4];
542
543 if(sdci[8] != 10000)
544 {
545 r*=sdci[8];
546 r/=10000;
547 }
548
549 r/=10000;
550
551 int32_t color=sdci[7]/10000;
552
553 fixed ra1=itofix(sdci[11]%10000)/10000;
554 fixed ra2=itofix(sdci[11]/10000);
555 fixed ra=ra1+ra2;
556 ra = (ra/360)*256;
557
558
559 fixed a1=itofix(sdci[5]%10000)/10000;
560 fixed a2=itofix(sdci[5]/10000);
561 fixed sa=a1+a2;
562 sa = (sa/360)*256;
563
564 a1=itofix(sdci[6]%10000)/10000;
565 a2=itofix(sdci[6]/10000);
566 fixed ea=a1+a2;
567 ea = (ea/360)*256;
568
569 if(sdci[11]!=0) //rotation
570 {
571 int32_t rx=sdci[9]/10000;
572 int32_t ry=sdci[10]/10000;
573
574 cx=rx + fixtoi((fixcos(ra) * (cx - rx) - fixsin(ra) * (cy - ry))); //x1
575 cy=ry + fixtoi((fixsin(ra) * (cx - rx) + fixcos(ra) * (cy - ry))); //y1
576 ea-=ra;
577 sa-=ra;
578 }
579
580 int32_t fx=cx+fixtoi(fixcos(-(ea+sa)/2)*r/2);
581 int32_t fy=cy+fixtoi(fixsin(-(ea+sa)/2)*r/2);
582
583 if(sdci[12]) //closed
584 {
585 if(sdci[13]) //filled
586 {
587 clear_bitmap(prim_bmp);
588 arc(prim_bmp, cx+xoffset, cy+yoffset, sa, ea, int32_t(r), color);
589 line(prim_bmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-sa)*r), cy+yoffset+fixtoi(fixsin(-sa)*r), color);
590 line(prim_bmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-ea)*r), cy+yoffset+fixtoi(fixsin(-ea)*r), color);
591 int fillx = zc_max(0,fx)+xoffset;
592 int filly = zc_max(0,fy)+yoffset;
593 zprint2("Screen->Arc fill at prim_bmp (%d,%d) - 512x512\n", fillx, filly);
594 floodfill(prim_bmp, fillx, filly, color);
595
596 if(sdci[14]/10000<=127) //translucent
597 {
598 draw_trans_sprite(bmp, prim_bmp, 0,0);
599 }
600 else
601 {
602 draw_sprite(bmp, prim_bmp, 0,0);
603 }
604 }
605 else
606 {
607 arc(bmp, cx+xoffset, cy+yoffset, sa, ea, int32_t(r), color);
608 line(bmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-sa)*r), cy+yoffset+fixtoi(fixsin(-sa)*r), color);
609 line(bmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-ea)*r), cy+yoffset+fixtoi(fixsin(-ea)*r), color);
610 }
611 }
612 else
613 {
614 if(sdci[14]/10000<=127) //translucent
615 {
616 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
617 }
618
619 arc(bmp, cx+xoffset, cy+yoffset, sa, ea, int32_t(r), color);
620 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
621 }
622 }
623
624
625 1850 void do_ellipser(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
626 {
627 //sdci[1]=layer
628 //sdci[2]=x
629 //sdci[3]=y
630 //sdci[4]=radiusx
631 //sdci[5]=radiusy
632 //sdci[6]=color
633 //sdci[7]=scale factor
634 //sdci[8]=rotation anchor x
635 //sdci[9]=rotation anchor y
636 //sdci[10]=rotation angle
637 //sdci[11]=fill
638 //sdci[12]=opacity
639
640
1/2
✓ Branch 0 taken 1850 times.
✗ Branch 1 not taken.
1850 if(sdci[7]==0) //scale
641 {
642 return;
643 }
644
645 1850 int32_t x1=sdci[2]/10000;
646 1850 int32_t y1=sdci[3]/10000;
647 1850 int32_t radx=sdci[4]/10000;
648 1850 radx*=sdci[7]/10000;
649 1850 int32_t rady=sdci[5]/10000;
650 1850 rady*=sdci[7]/10000;
651 1850 int32_t color=sdci[6]/10000;
652 1850 float rotation = sdci[10]/10000;
653
654 1850 int32_t rx=sdci[8]/10000;
655 1850 int32_t ry=sdci[9]/10000;
656 1850 fixed ra1=itofix(sdci[10]%10000)/10000;
657 1850 fixed ra2=itofix(sdci[10]/10000);
658 1850 fixed ra=ra1+ra2;
659 1850 ra = (ra/360)*256;
660
661 int32_t xy[2];
662 1850 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
663 1850 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
664 1850 x1=xy[0];
665 1850 y1=xy[1];
666
667
6/8
✓ Branch 0 taken 1746 times.
✓ Branch 1 taken 104 times.
✓ Branch 2 taken 1687 times.
✓ Branch 3 taken 59 times.
✓ Branch 4 taken 1687 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1687 times.
1850 if(radx<1||rady<1||radx>255||rady>255) return;
668
669 1687 BITMAP* bitty = script_drawing_commands.AquireSubBitmap(radx*2+1, rady*2+1);
670
671
2/2
✓ Branch 0 taken 1630 times.
✓ Branch 1 taken 57 times.
1687 if(sdci[11]) //filled
672 {
673
674
2/2
✓ Branch 0 taken 1024 times.
✓ Branch 1 taken 606 times.
1630 if(sdci[12]/10000<128) //translucent
675 {
676 1024 clear_bitmap(prim_bmp);
677
1/2
✓ Branch 0 taken 1024 times.
✗ Branch 1 not taken.
1024 ellipsefill(bitty, radx, rady, radx, rady, color==0?255:color);
678 1024 rotate_sprite(prim_bmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
679 1024 draw_trans_sprite(bmp, prim_bmp, 0, 0);
680 1024 }
681 else // no opacity
682 {
683
1/2
✓ Branch 0 taken 606 times.
✗ Branch 1 not taken.
606 ellipsefill(bitty, radx, rady, radx, rady, color==0?255:color);
684 606 rotate_sprite(bmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
685 }
686 1630 }
687 else //not filled
688 {
689
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 43 times.
57 if(sdci[12]/10000<128) //translucent
690 {
691 14 clear_bitmap(prim_bmp);
692
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 ellipse(bitty, radx, rady, radx, rady, color==0?255:color);
693 14 rotate_sprite(prim_bmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
694 14 draw_trans_sprite(bmp, prim_bmp, 0, 0);
695 14 }
696 else // no opacity
697 {
698
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
43 ellipse(bitty, radx, rady, radx, rady, color==0?255:color);
699 43 rotate_sprite(bmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
700 }
701 }
702
703 // Since 0 is the transparent color, the stuff above will fail if the ellipse color is also 0.
704 // Instead, it uses color 255 and replaces it afterward. That'll also screw up color 255 around
705 // the ellipse, but it shouldn't be used anyway.
706
1/2
✓ Branch 0 taken 1687 times.
✗ Branch 1 not taken.
1687 if(color==0)
707 {
708 // This is very slow, so check the smallest possible square
709 int32_t endx=zc_min(bmp->w-1, x1+zc_max(radx, rady));
710 int32_t endy=zc_min(bmp->h-1, y1+zc_max(radx, rady));
711
712 for(int32_t y=zc_max(0, y1-zc_max(radx, rady)); y<=endy; y++)
713 for(int32_t x=zc_max(0, x1-zc_max(radx, rady)); x<=endx; x++)
714 if(getpixel(bmp, x, y)==255)
715 putpixel(bmp, x, y, 0);
716 }
717
718 1687 script_drawing_commands.ReleaseSubBitmap(bitty);
719 1850 }
720
721
722 2351475 void do_liner(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
723 {
724 //sdci[1]=layer
725 //sdci[2]=x
726 //sdci[3]=y
727 //sdci[4]=x2
728 //sdci[5]=y2
729 //sdci[6]=color
730 //sdci[7]=scale factor
731 //sdci[8]=rotation anchor x
732 //sdci[9]=rotation anchor y
733 //sdci[10]=rotation angle
734 //sdci[11]=opacity
735
1/2
✓ Branch 0 taken 2351475 times.
✗ Branch 1 not taken.
2351475 if(sdci[7]==0) //scale
736 {
737 return;
738 }
739
740 2351475 int32_t x1=sdci[2]/10000;
741 2351475 int32_t y1=sdci[3]/10000;
742 2351475 int32_t x2=sdci[4]/10000;
743 2351475 int32_t y2=sdci[5]/10000;
744
745
2/2
✓ Branch 0 taken 1903153 times.
✓ Branch 1 taken 448322 times.
2351475 if(sdci[7] != 10000)
746 {
747 448322 int32_t w=x2-x1+1;
748 448322 int32_t h=y2-y1+1;
749 448322 int32_t w2=int32_t(w*((double)sdci[7]/10000.0));
750 448322 int32_t h2=int32_t(h*((double)sdci[7]/10000.0));
751 448322 x1=x1-((w2-w)/2);
752 448322 x2=x2+((w2-w)/2);
753 448322 y1=y1-((h2-h)/2);
754 448322 y2=y2+((h2-h)/2);
755 448322 }
756
757 2351475 int32_t color=sdci[6]/10000;
758
759
1/2
✓ Branch 0 taken 2351475 times.
✗ Branch 1 not taken.
2351475 if(sdci[11]/10000<=127) //translucent
760 {
761 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
762 }
763
764
2/2
✓ Branch 0 taken 939459 times.
✓ Branch 1 taken 1412016 times.
2351475 if(sdci[10]!=0) //rotation
765 {
766 int32_t xy[4];
767 1412016 int32_t rx=sdci[8]/10000;
768 1412016 int32_t ry=sdci[9]/10000;
769 1412016 fixed ra1=itofix(sdci[10]%10000)/10000;
770 1412016 fixed ra2=itofix(sdci[10]/10000);
771 1412016 fixed ra=ra1+ra2;
772
773 1412016 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
774 1412016 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
775 1412016 xy[ 2]=rx + fixtoi((fixcos(ra) * (x2 - rx) - fixsin(ra) * (y2 - ry))); //x2
776 1412016 xy[ 3]=ry + fixtoi((fixsin(ra) * (x2 - rx) + fixcos(ra) * (y2 - ry))); //y2
777 1412016 x1=xy[0];
778 1412016 y1=xy[1];
779 1412016 x2=xy[2];
780 1412016 y2=xy[3];
781 1412016 }
782
783 2351475 line(bmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
784 2351475 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
785 2351475 }
786
787 void do_linesr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
788 {
789 //sdci[1]=layer
790 //sdci[2]=array[10] = { x, y, x2, y2, colour, scale, rx, ry, angle, opacity }
791
792 //sdci[2]=x
793 //sdci[3]=y
794 //sdci[4]=x2
795 //sdci[5]=y2
796 //sdci[6]=color
797 //sdci[7]=scale factor
798 //sdci[8]=rotation anchor x
799 //sdci[9]=rotation anchor y
800 //sdci[10]=rotation angle
801 //sdci[11]=opacity
802 //if(sdci[7]==0) //scale
803 //{
804 // return;
805 //}
806
807 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
808
809 if(!v_ptr)
810 {
811 al_trace("Screen->PutPixels: Vector pointer is null! Internal error. \n");
812 return;
813 }
814
815 std::vector<int32_t> &v = *v_ptr;
816
817 if(v.empty())
818 return;
819
820 int32_t* pos = &v[0];
821 int32_t sz = v.size();
822
823 for ( int32_t q = 0; q < sz; q+=10 )
824 {
825
826 int32_t x1 = v.at(q);
827 //Z_scripterrlog("Lines( x1 ) is: %d\n", x1);
828 int32_t y1 = v.at(q+1);
829 //Z_scripterrlog("Lines( x2 ) is: %d\n", y1);
830 int32_t x2 = v.at(q+2);
831 //Z_scripterrlog("Lines( x2 ) is: %d\n", x2);
832 int32_t y2 = v.at(q+3);
833 //Z_scripterrlog("Lines( y2 ) is: %d\n", y2);
834 int32_t color = v.at(q+4);
835 //Z_scripterrlog("Lines( colour ) is: %d\n", color);
836 //Z_scripterrlog("Lines( scale ) is: %d\n", v.at(q+5));
837 if (v.at(q+5) == 0) { Z_scripterrlog("Lines() aborting due to scale\n"); return; }//scale
838
839 if( v.at(q+5) != 10000)
840 {
841 int32_t w=x2-x1+1;
842 int32_t h=y2-y1+1;
843 int32_t w2=int32_t(w*((double)v.at(q+5)));
844 int32_t h2=int32_t(h*((double)v.at(q+5)));
845 x1=x1-((w2-w)/2);
846 x2=x2+((w2-w)/2);
847 y1=y1-((h2-h)/2);
848 y2=y2+((h2-h)/2);
849 }
850
851
852 //Z_scripterrlog("Lines( opacity ) is: %d\n", v.at(q+9));
853 if(v.at(q+9) <= 127) //translucent
854 {
855 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
856 }
857 else drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
858 //Z_scripterrlog("Lines( rotation ) is: %d\n", v.at(q+8));
859 //Z_scripterrlog("Lines( rot_x ) is: %d\n", v.at(q+6));
860 //Z_scripterrlog("Lines( rot_x ) is: %d\n", v.at(q+7));
861 if( v.at(q+8) !=0 ) //rotation
862 {
863 int32_t xy[4];
864
865 int32_t rx = v.at(q+6);
866
867 int32_t ry = v.at(q+7);
868
869 fixed ra1=itofix(v.at(q+8) % 1);
870 fixed ra2=itofix(v.at(q+8));
871 fixed ra=ra1+ra2;
872
873 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
874 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
875 xy[ 2]=rx + fixtoi((fixcos(ra) * (x2 - rx) - fixsin(ra) * (y2 - ry))); //x2
876 xy[ 3]=ry + fixtoi((fixsin(ra) * (x2 - rx) + fixcos(ra) * (y2 - ry))); //y2
877 x1=xy[0];
878 y1=xy[1];
879 x2=xy[2];
880 y2=xy[3];
881 }
882 //Z_scripterrlog("Lines( xofs ) is: %d\n", xoffset);
883 //Z_scripterrlog("Lines( yofs ) is: %d\n", yoffset);
884 line(bmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
885 }
886 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
887 }
888
889 1080 void do_polygonr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
890 {
891 //sdci[1]=layer
892 //sdci[2]=point count
893 //sdci[3]array[]
894 //sdci[4] = colour
895 //sdci[5] = opacity
896
897 1080 int32_t col = sdci[4]/10000;
898 1080 int32_t op = sdci[5]/10000;
899
900 1080 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
901
902
1/2
✓ Branch 0 taken 1080 times.
✗ Branch 1 not taken.
1080 if(!v_ptr)
903 {
904 al_trace("Screen->Polygon: Vector pointer is null! Internal error. \n");
905 return;
906 }
907
908 1080 std::vector<int32_t> &v = *v_ptr;
909
910
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1080 times.
1080 if(v.empty())
911 return;
912
913 1080 int32_t* pos = &v[0];
914 1080 int32_t sz = v.size();
915 1080 int32_t numpoints = (sdci[2]/10000);
916
1/2
✓ Branch 0 taken 1080 times.
✗ Branch 1 not taken.
1080 if(sz & 1) --sz; //even amount only
917
1/2
✓ Branch 0 taken 1080 times.
✗ Branch 1 not taken.
1080 if(numpoints > sz/2) //cap to array
918 numpoints = sz/2;
919
1/2
✓ Branch 0 taken 1080 times.
✗ Branch 1 not taken.
1080 if(numpoints < 1)
920 return; //Don't draw 0 or negative point count
921
922
2/2
✓ Branch 0 taken 6480 times.
✓ Branch 1 taken 1080 times.
7560 for (int32_t i = 0; i < sz; i += 2)
923 {
924 6480 pos[i] += xoffset;
925 6480 pos[i + 1] += yoffset;
926 6480 }
927
928
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1080 times.
1080 if(op <= 127) //translucent
929 {
930 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
931 }
932 1080 else drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
933
934 1080 polygon(bmp, numpoints, (int32_t*)pos, col);
935 1080 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
936 1080 }
937
938 void bmp_do_polygonr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
939 {
940 //sdci[1]=layer
941 //sdci[2]=point count
942 //sdci[3]array[]
943 //sdci[4] = colour
944 //sdci[5] = opacity
945
946 int32_t col = sdci[4]/10000;
947 int32_t op = sdci[5]/10000;
948
949 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
950 {
951 Z_scripterrlog("bitmap->Polygon() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
952 return;
953 }
954 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
955 if ( refbmp == NULL ) return;
956
957 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
958
959 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
960
961 if(!v_ptr)
962 {
963 al_trace("bitmap->Polygon: Vector pointer is null! Internal error. \n");
964 return;
965 }
966
967 std::vector<int32_t> &v = *v_ptr;
968
969 if(v.empty())
970 return;
971
972 int32_t* pos = &v[0];
973 int32_t sz = v.size();
974 int32_t numpoints = (sdci[2]/10000);
975 if(sz & 1) --sz; //even amount only
976 if(numpoints > sz/2) //cap to array
977 numpoints = sz/2;
978 if(numpoints < 1)
979 return; //Don't draw 0 or negative point count
980
981 for (int32_t i = 0; i < sz; i += 2)
982 {
983 pos[i] += xoffset;
984 pos[i + 1] += yoffset;
985 }
986
987 if(op <= 127) //translucent
988 {
989 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
990 }
991 else drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
992
993 polygon(refbmp, numpoints, (int32_t*)pos, col);
994 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
995 }
996
997 void do_spliner(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
998 {
999 /* layer, x1, y1, x2, y2, x3, y3, x4, y4, color, opacity */
1000
1001 int32_t points[8] = { xoffset + (sdci[2]/10000), yoffset + (sdci[3]/10000),
1002 xoffset + (sdci[4]/10000), yoffset + (sdci[5]/10000),
1003 xoffset + (sdci[6]/10000), yoffset + (sdci[7]/10000),
1004 xoffset + (sdci[8]/10000), yoffset + (sdci[9]/10000)
1005 };
1006
1007 if(sdci[11]/10000 < 128) //translucent
1008 {
1009 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
1010 }
1011
1012 spline(bmp, points, sdci[10]/10000);
1013
1014 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
1015 }
1016
1017
1018 404879 void do_putpixelr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1019 {
1020 //sdci[1]=layer
1021 //sdci[2]=x
1022 //sdci[3]=y
1023 //sdci[4]=color
1024 //sdci[5]=rotation anchor x
1025 //sdci[6]=rotation anchor y
1026 //sdci[7]=rotation angle
1027 //sdci[8]=opacity
1028 404879 int32_t x1=sdci[2]/10000;
1029 404879 int32_t y1=sdci[3]/10000;
1030 404879 int32_t color=sdci[4]/10000;
1031
1032
2/2
✓ Branch 0 taken 404863 times.
✓ Branch 1 taken 16 times.
404879 if(sdci[8]/10000<=127) //translucent
1033 {
1034 16 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
1035 16 }
1036
1037
1/2
✓ Branch 0 taken 404879 times.
✗ Branch 1 not taken.
404879 if(sdci[7]!=0) //rotation
1038 {
1039 int32_t xy[2];
1040 int32_t rx=sdci[5]/10000;
1041 int32_t ry=sdci[6]/10000;
1042 fixed ra1=itofix(sdci[7]%10000)/10000;
1043 fixed ra2=itofix(sdci[7]/10000);
1044 fixed ra=ra1+ra2;
1045
1046 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
1047 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
1048 x1=xy[0];
1049 y1=xy[1];
1050 }
1051
1052 404879 putpixel(bmp, x1+xoffset, y1+yoffset, color);
1053 404879 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
1054 404879 }
1055
1056 void do_putpixelsr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1057 {
1058 //Z_scripterrlog("Starting putpixels()%s\n");
1059 //sdci[1]=layer
1060 //sdci[2]=array {x,y,colour,opacity}
1061 //sdci[3]=rotation anchor x
1062 //sdci[4]=rotation anchor y
1063 //sdci[5]=rotation angle
1064
1065
1066 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
1067
1068 if(!v_ptr)
1069 {
1070 al_trace("Screen->PutPixels: Vector pointer is null! Internal error. \n");
1071 return;
1072 }
1073
1074 std::vector<int32_t> &v = *v_ptr;
1075
1076 if(v.empty())
1077 return;
1078
1079 int32_t* pos = &v[0];
1080 int32_t sz = v.size();
1081
1082
1083 int32_t x1 = 0;
1084 int32_t y1 = 0;
1085
1086 for ( int32_t q = 0; q < sz; q+=4 )
1087 {
1088 x1 = v.at(q); //pos[q];
1089 y1 = v.at(q+1); //pos[q+1];
1090 if(sdci[5]!=0) //rotation
1091 {
1092 int32_t xy[2];
1093 int32_t rx=sdci[3]/10000;
1094 int32_t ry=sdci[4]/10000;
1095 fixed ra1=itofix(sdci[5]%10000)/10000;
1096 fixed ra2=itofix(sdci[5]/10000);
1097 fixed ra=ra1+ra2;
1098
1099 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
1100 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
1101 x1=xy[0];
1102 y1=xy[1];
1103 }
1104 if ( v.at(q+3) /*pos[q+3]*/ < 128 ) drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
1105 else drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
1106 putpixel(bmp, x1+xoffset, y1+yoffset, v.at(q+2) /*pos[q+2]*/);
1107 }
1108 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
1109 }
1110
1111 1546047 void do_drawtiler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1112 {
1113 //sdci[1]=layer
1114 //sdci[2]=x
1115 //sdci[3]=y
1116 //sdci[4]=tile
1117 //sdci[5]=tile width
1118 //sdci[6]=tile height
1119 //sdci[7]=color (cset)
1120 //sdci[8]=scale x
1121 //sdci[9]=scale y
1122 //sdci[10]=rotation anchor x
1123 //sdci[11]=rotation anchor y
1124 //sdci[12]=rotation angle
1125 //sdci[13]=flip
1126 //sdci[14]=transparency
1127 //sdci[15]=opacity
1128
1129 1546047 int32_t w = sdci[5]/10000;
1130 1546047 int32_t h = sdci[6]/10000;
1131
1132
4/8
✓ Branch 0 taken 1546047 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1546047 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1546047 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1546047 times.
1546047 if(w < 1 || h < 1 || h > 20 || w > 20)
1133 {
1134 return;
1135 }
1136
1137 1546047 int32_t xscale=sdci[8]/10000;
1138 1546047 int32_t yscale=sdci[9]/10000;
1139 1546047 int32_t rx = sdci[10]/10000;
1140 1546047 int32_t ry = sdci[11]/10000;
1141 1546047 float rotation=sdci[12]/10000;
1142 1546047 int32_t flip=(sdci[13]/10000)&3;
1143 1546047 bool transparency=sdci[14]!=0;
1144 1546047 int32_t opacity=sdci[15]/10000;
1145 1546047 int32_t color=sdci[7]/10000;
1146
1147 1546047 int32_t x1=sdci[2]/10000;
1148 1546047 int32_t y1=sdci[3]/10000;
1149
1150 //don't scale if it's not safe to do so
1151 1546047 bool canscale = true;
1152
1153
3/4
✓ Branch 0 taken 1525402 times.
✓ Branch 1 taken 20645 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1525402 times.
1546047 if(xscale==0||yscale==0)
1154 {
1155 20645 return;
1156 }
1157
1158
3/4
✓ Branch 0 taken 138965 times.
✓ Branch 1 taken 1386437 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 138965 times.
1525402 if(xscale<=0||yscale<=0)
1159 1386437 canscale = false; //default size
1160
1161
4/4
✓ Branch 0 taken 138965 times.
✓ Branch 1 taken 1386437 times.
✓ Branch 2 taken 131077 times.
✓ Branch 3 taken 1255360 times.
1525402 if((xscale>0 && yscale>0) || rotation) //scaled or rotated
1162 {
1163 270042 BITMAP* pbitty = script_drawing_commands.AquireSubBitmap(w*16, h*16);
1164
1165
1/2
✓ Branch 0 taken 270042 times.
✗ Branch 1 not taken.
270042 if(transparency) //transparency
1166 {
1167 270042 TileHelper::OverTile(pbitty, (sdci[4]/10000), 0, 0, w, h, color, flip);
1168 270042 }
1169 else //no transparency
1170 {
1171 TileHelper::OldPutTile(pbitty, (sdci[4]/10000), 0, 0, w, h, color, flip);
1172 }
1173
1174
2/2
✓ Branch 0 taken 134765 times.
✓ Branch 1 taken 135277 times.
270042 if(rotation != 0)
1175 {
1176 //low negative values indicate no anchor-point rotation
1177
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 134765 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
134765 if(rx>-777||ry>-777)
1178 {
1179 int32_t xy[2];
1180 134765 fixed ra1=itofix(sdci[12]%10000)/10000;
1181 134765 fixed ra2=itofix(sdci[12]/10000);
1182 134765 fixed ra=ra1+ra2;
1183 134765 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
1184 134765 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
1185 134765 x1=xy[0];
1186 134765 y1=xy[1];
1187 134765 }
1188
1189
2/2
✓ Branch 0 taken 3688 times.
✓ Branch 1 taken 131077 times.
134765 if(canscale) //scale first
1190 {
1191 //damnit all, .. fixme.
1192
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3688 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3688 times.
3688 BITMAP* tempbit = create_bitmap_ex(8, xscale>512?512:xscale, yscale>512?512:yscale);
1193 3688 clear_bitmap(tempbit);
1194
1195 3688 stretch_sprite(tempbit, pbitty, 0, 0, xscale, yscale);
1196
1197
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3688 times.
3688 if(opacity < 128)
1198 {
1199 clear_bitmap(prim_bmp);
1200 rotate_sprite(prim_bmp, tempbit, 0, 0, degrees_to_fixed(rotation));
1201 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1202 }
1203 else
1204 {
1205 3688 rotate_sprite(bmp, tempbit, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
1206 }
1207
1208 3688 destroy_bitmap(tempbit);
1209 3688 }
1210 else //no scale
1211 {
1212
2/2
✓ Branch 0 taken 3586 times.
✓ Branch 1 taken 127491 times.
131077 if(opacity < 128)
1213 {
1214 3586 clear_bitmap(prim_bmp);
1215 3586 rotate_sprite(prim_bmp, pbitty, 0, 0, degrees_to_fixed(rotation));
1216 3586 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1217 3586 }
1218 else
1219 {
1220 127491 rotate_sprite(bmp, pbitty, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
1221 }
1222 }
1223 134765 }
1224 else //scale only
1225 {
1226
1/2
✓ Branch 0 taken 135277 times.
✗ Branch 1 not taken.
135277 if(canscale)
1227 {
1228
2/2
✓ Branch 0 taken 2832 times.
✓ Branch 1 taken 132445 times.
135277 if(opacity<128)
1229 {
1230 2832 clear_bitmap(prim_bmp);
1231 2832 stretch_sprite(prim_bmp, pbitty, 0, 0, xscale, yscale);
1232 2832 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1233 2832 }
1234 else
1235 {
1236 132445 stretch_sprite(bmp, pbitty, x1+xoffset, y1+yoffset, xscale, yscale);
1237 }
1238 135277 }
1239 else //error -do not scale
1240 {
1241 if(opacity<128)
1242 {
1243 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1244 }
1245 else
1246 {
1247 draw_sprite(bmp, pbitty, x1+xoffset, y1+yoffset);
1248 }
1249 }
1250 }
1251
1252 270042 script_drawing_commands.ReleaseSubBitmap(pbitty);
1253
1254 270042 }
1255 else // no scale or rotation
1256 {
1257
2/2
✓ Branch 0 taken 1227906 times.
✓ Branch 1 taken 27454 times.
1255360 if(transparency)
1258 {
1259
2/2
✓ Branch 0 taken 224767 times.
✓ Branch 1 taken 1003139 times.
1227906 if(opacity<=127)
1260 224767 TileHelper::OverTileTranslucent(bmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip, opacity);
1261 else
1262 1003139 TileHelper::OverTile(bmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip);
1263 1227906 }
1264 else
1265 {
1266
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27454 times.
27454 if(opacity<=127)
1267 TileHelper::PutTileTranslucent(bmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip, opacity);
1268 else
1269 27454 TileHelper::OldPutTile(bmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip);
1270 }
1271 }
1272 1546047 }
1273
1274 void do_drawtilecloakedr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1275 {
1276 //sdci[1]=layer
1277 //sdci[2]=x
1278 //sdci[3]=y
1279 //sdci[4]=tile
1280 //sdci[5]=tile width
1281 //sdci[6]=tile height
1282 //sdci[7]=flip
1283
1284 int32_t w = sdci[5]/10000;
1285 int32_t h = sdci[6]/10000;
1286
1287 if(w < 1 || h < 1 || h > 20 || w > 20)
1288 {
1289 return;
1290 }
1291
1292 int32_t flip=(sdci[7]/10000)&3;
1293
1294 int32_t x1=sdci[2]/10000;
1295 int32_t y1=sdci[3]/10000;
1296
1297 TileHelper::OverTileCloaked(bmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, flip);
1298 }
1299
1300
1301 2712759 void do_drawcombor(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1302 {
1303 //sdci[1]=layer
1304 //sdci[2]=x
1305 //sdci[3]=y
1306 //sdci[4]=combo
1307 //sdci[5]=tile width
1308 //sdci[6]=tile height
1309 //sdci[7]=color (cset)
1310 //sdci[8]=scale x
1311 //sdci[9]=scale y
1312 //sdci[10]=rotation anchor x
1313 //sdci[11]=rotation anchor y
1314 //sdci[12]=rotation angle
1315 //sdci[13]=frame
1316 //sdci[14]=flip
1317 //sdci[15]=transparency
1318 //sdci[16]=opacity
1319
1320 2712759 int32_t w = sdci[5]/10000;
1321 2712759 int32_t h = sdci[6]/10000;
1322
1323
4/8
✓ Branch 0 taken 2712759 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2712759 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2712759 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 2712759 times.
2712759 if(w<1||h<1||h>20||w>20)
1324 {
1325 return;
1326 }
1327 2712759 int32_t cmb = (sdci[4]/10000);
1328
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2712759 times.
2712759 if((unsigned)cmb >= MAXCOMBOS)
1329 {
1330 Z_scripterrlog("DrawCombo() cannot draw combo '%d', as it is out of bounds.\n", cmb);
1331 return;
1332 }
1333
1334 2712759 int32_t xscale=sdci[8]/10000;
1335 2712759 int32_t yscale=sdci[9]/10000;
1336 2712759 int32_t rx = sdci[10]/10000; //these work now
1337 2712759 int32_t ry = sdci[11]/10000; //these work now
1338 2712759 float rotation=sdci[12]/10000;
1339
1340 2712759 bool transparency=sdci[15]!=0;
1341 2712759 int32_t opacity=sdci[16]/10000;
1342 2712759 int32_t color=sdci[7]/10000;
1343 2712759 int32_t x1=sdci[2]/10000;
1344 2712759 int32_t y1=sdci[3]/10000;
1345
1346 2712759 auto& c = GET_DRAWING_COMBO(cmb);
1347 2712759 int32_t tiletodraw = combo_tile(c, x1, y1);
1348 2712759 int32_t flip = ((sdci[14]/10000) & 3) ^ c.flip;
1349 2712759 int32_t skiprows=c.skipanimy;
1350
1351
1352 //don't scale if it's not safe to do so
1353 2712759 bool canscale = true;
1354
1355
3/4
✓ Branch 0 taken 2712708 times.
✓ Branch 1 taken 51 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2712708 times.
2712759 if(xscale==0||yscale==0)
1356 {
1357 51 return;
1358 }
1359
1360
3/4
✓ Branch 0 taken 22604 times.
✓ Branch 1 taken 2690104 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 22604 times.
2712708 if(xscale<=0||yscale<=0)
1361 2690104 canscale = false; //default size
1362
1363
4/4
✓ Branch 0 taken 22604 times.
✓ Branch 1 taken 2690104 times.
✓ Branch 2 taken 98637 times.
✓ Branch 3 taken 2591467 times.
2712708 if((xscale>0 && yscale>0) || rotation) //scaled or rotated
1364 {
1365 121241 BITMAP* pbitty = script_drawing_commands.AquireSubBitmap(w*16, h*16); //-pbitty in the hisouse. :D
1366
1367
2/2
✓ Branch 0 taken 120205 times.
✓ Branch 1 taken 1036 times.
121241 if(transparency)
1368 {
1369 120205 TileHelper::OverTile(pbitty, tiletodraw, 0, 0, w, h, color, flip, skiprows);
1370 120205 }
1371 else //no transparency
1372 {
1373 1036 TileHelper::OldPutTile(pbitty, tiletodraw, 0, 0, w, h, color, flip, skiprows);
1374 }
1375
1376
2/2
✓ Branch 0 taken 98855 times.
✓ Branch 1 taken 22386 times.
121241 if(rotation != 0) // rotate
1377 {
1378 //fixed point sucks ;0
1379
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 98855 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
98855 if(rx>-777||ry>-777) //set the rotation anchor and rotate around that
1380 {
1381 int32_t xy[2];
1382 98855 fixed ra1=itofix(sdci[12]%10000)/10000;
1383 98855 fixed ra2=itofix(sdci[12]/10000);
1384 98855 fixed ra=ra1+ra2;
1385 98855 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
1386 98855 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
1387 98855 x1=xy[0];
1388 98855 y1=xy[1];
1389 98855 }
1390
1391
2/2
✓ Branch 0 taken 218 times.
✓ Branch 1 taken 98637 times.
98855 if(canscale) //scale first
1392 {
1393
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 218 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 218 times.
218 BITMAP* tempbit = create_bitmap_ex(8, xscale>512?512:xscale, yscale>512?512:yscale);
1394 218 clear_bitmap(tempbit);
1395
1396 218 stretch_sprite(tempbit, pbitty, 0, 0, xscale, yscale);
1397
1398
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 218 times.
218 if(opacity < 128)
1399 {
1400 clear_bitmap(prim_bmp);
1401 rotate_sprite(prim_bmp, tempbit, 0, 0, degrees_to_fixed(rotation));
1402 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1403 }
1404 else
1405 {
1406 218 rotate_sprite(bmp, tempbit, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
1407 }
1408
1409 218 destroy_bitmap(tempbit);
1410 218 }
1411 else //no scale
1412 {
1413
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 98637 times.
98637 if(opacity < 128)
1414 {
1415 clear_bitmap(prim_bmp);
1416 rotate_sprite(prim_bmp, pbitty, 0, 0, degrees_to_fixed(rotation));
1417 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1418 }
1419 else
1420 {
1421 98637 rotate_sprite(bmp, pbitty, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
1422 }
1423 }
1424 98855 }
1425 else //scale only
1426 {
1427
1/2
✓ Branch 0 taken 22386 times.
✗ Branch 1 not taken.
22386 if(canscale)
1428 {
1429
2/2
✓ Branch 0 taken 9333 times.
✓ Branch 1 taken 13053 times.
22386 if(opacity<128)
1430 {
1431 9333 clear_bitmap(prim_bmp);
1432 9333 stretch_sprite(prim_bmp, pbitty, 0, 0, xscale, yscale);
1433 9333 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1434 9333 }
1435 else
1436 {
1437 13053 stretch_sprite(bmp, pbitty, x1+xoffset, y1+yoffset, xscale, yscale);
1438 }
1439 22386 }
1440 else //error -do not scale
1441 {
1442 if(opacity<128)
1443 {
1444 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1445 }
1446 else
1447 {
1448 draw_sprite(bmp, pbitty, x1+xoffset, y1+yoffset);
1449 }
1450 }
1451 }
1452
1453 121241 script_drawing_commands.ReleaseSubBitmap(pbitty); //rap sucks
1454 121241 }
1455 else // no scale or rotation
1456 {
1457
1/2
✓ Branch 0 taken 2591467 times.
✗ Branch 1 not taken.
2591467 if(transparency)
1458 {
1459
2/2
✓ Branch 0 taken 63540 times.
✓ Branch 1 taken 2527927 times.
2591467 if(opacity<=127)
1460 63540 TileHelper::OverTileTranslucent(bmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, opacity, skiprows);
1461 else
1462 2527927 TileHelper::OverTile(bmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, skiprows);
1463 2591467 }
1464 else
1465 {
1466 if(opacity<=127)
1467 TileHelper::PutTileTranslucent(bmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, opacity, skiprows);
1468 else
1469 TileHelper::OldPutTile(bmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, skiprows);
1470 }
1471 }
1472 2712759 }
1473
1474 void do_drawcombocloakedr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1475 {
1476 //sdci[1]=layer
1477 //sdci[2]=x
1478 //sdci[3]=y
1479 //sdci[4]=combo
1480 //sdci[5]=tile width
1481 //sdci[6]=tile height
1482 //sdci[7]=flip
1483
1484 int32_t w = sdci[5]/10000;
1485 int32_t h = sdci[6]/10000;
1486
1487 if(w<1||h<1||h>20||w>20)
1488 {
1489 return;
1490 }
1491 int32_t cmb = (sdci[4]/10000);
1492 if((unsigned)cmb >= MAXCOMBOS)
1493 {
1494 Z_scripterrlog("DrawComboCloaked() cannot draw combo '%d', as it is out of bounds.\n", cmb);
1495 return;
1496 }
1497
1498 int32_t x1=sdci[2]/10000;
1499 int32_t y1=sdci[3]/10000;
1500
1501 auto& c = GET_DRAWING_COMBO(cmb);
1502 int32_t tiletodraw = combo_tile(c, x1, y1);
1503 int32_t flip = ((sdci[7]/10000) & 3) ^ c.flip;
1504 int32_t skiprows=c.skipanimy;
1505
1506 TileHelper::OverTileCloaked(bmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, flip, skiprows);
1507 }
1508
1509
1510 5290540 void do_fasttiler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1511 {
1512 /* layer, x, y, tile, color opacity */
1513
1514 5290540 int32_t opacity = sdci[6]/10000;
1515 5290540 int x = xoffset+(sdci[2]/10000);
1516 5290540 int y = yoffset+(sdci[3]/10000);
1517
1518
2/2
✓ Branch 0 taken 153668 times.
✓ Branch 1 taken 5136872 times.
5290540 if(opacity < 128)
1519 153668 overtiletranslucent16(bmp, sdci[4]/10000, x, y, sdci[5]/10000, 0, opacity);
1520 else
1521 5136872 overtile16(bmp, sdci[4]/10000, x, y, sdci[5]/10000, 0);
1522 5290540 }
1523
1524 void do_fasttilesr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1525 {
1526 /* layer, x, y, tile, color opacity */
1527
1528 //sdci[1]=layer
1529 //sdci[2]=array {x,y,tile,colour,opacity}
1530
1531 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
1532
1533 if(!v_ptr)
1534 {
1535 al_trace("Screen->PutPixels: Vector pointer is null! Internal error. \n");
1536 return;
1537 }
1538
1539 std::vector<int32_t> &v = *v_ptr;
1540
1541 if(v.empty())
1542 return;
1543
1544 int32_t* pos = &v[0];
1545 int32_t sz = v.size();
1546
1547 for ( int32_t q = 0; q < sz; q+=5 )
1548 {
1549
1550 if(v.at(q+4) < 128)
1551 overtiletranslucent16(bmp, v.at(q+2), xoffset+(v.at(q)), yoffset+(v.at(q+1)), v.at(q+3), 0, v.at(q+4));
1552 else
1553 overtile16(bmp, v.at(q+2), xoffset+(v.at(q)), yoffset+(v.at(q+1)), v.at(q+3), 0);
1554 }
1555 }
1556
1557
1558
1559 22452549 void do_fastcombor(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1560 {
1561 /* layer, x, y, tile, color opacity */
1562
1563 22452549 int32_t opacity = sdci[6] / 10000;
1564 22452549 int32_t x1 = sdci[2] / 10000;
1565 22452549 int32_t y1 = sdci[3] / 10000;
1566
1567 22452549 int32_t cmb = (sdci[4]/10000);
1568
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22452549 times.
22452549 if((unsigned)cmb >= MAXCOMBOS)
1569 {
1570 Z_scripterrlog("FastCombo() cannot draw combo '%d', as it is out of bounds.\n", cmb);
1571 return;
1572 }
1573
1574 22452549 int x = xoffset+x1;
1575 22452549 int y = yoffset+y1;
1576
1577
2/2
✓ Branch 0 taken 177396 times.
✓ Branch 1 taken 22275153 times.
22452549 if(opacity < 128)
1578 {
1579 177396 overcomboblocktranslucent(bmp, x, y, cmb, sdci[5]/10000, 1, 1, 128);
1580 177396 }
1581 else
1582 {
1583 22275153 overcomboblock(bmp, x, y, cmb, sdci[5]/10000, 1, 1);
1584 }
1585 22452549 }
1586
1587 void do_fastcombosr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1588 {
1589 /* layer, x, y, combo, cset, opacity */
1590 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
1591
1592 if(!v_ptr)
1593 {
1594 al_trace("Screen->FastCombos: Vector pointer is null! Internal error. \n");
1595 return;
1596 }
1597
1598 std::vector<int32_t> &v = *v_ptr;
1599
1600 if(v.empty())
1601 return;
1602
1603 int32_t* pos = &v[0];
1604 int32_t sz = v.size();
1605
1606 for ( int32_t q = 0; q < sz; q+=5 )
1607 {
1608 if((unsigned)(v.at(q+2)) >= MAXCOMBOS)
1609 {
1610 Z_scripterrlog("FastCombos() cannot draw combo '%d', as it is out of bounds.\n", v.at(q+2));
1611 continue;
1612 }
1613 if(v.at(q+4) < 128)
1614 {
1615 overcomboblocktranslucent(bmp, xoffset+v.at(q), yoffset+v.at(q+1), v.at(q+2), v.at(q+3), 1, 1, 128);
1616
1617 }
1618 else
1619 {
1620 overcomboblock(bmp, xoffset+v.at(q), yoffset+v.at(q+1), v.at(q+2), v.at(q+3), 1, 1);
1621 }
1622 }
1623 }
1624
1625
1626
1627
1628 963845 void do_drawcharr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1629 {
1630 //broken 2.50.2 and earlier drawcharacter()
1631
2/2
✓ Branch 0 taken 18543 times.
✓ Branch 1 taken 945302 times.
963845 if ( get_qr(qr_BROKENCHARINTDRAWING) )
1632 {
1633 //sdci[1]=layer
1634 //sdci[2]=x
1635 //sdci[3]=y
1636 //sdci[4]=font
1637 //sdci[5]=color
1638 //sdci[6]=bg color
1639 //sdci[7]=strech x (width)
1640 //sdci[8]=stretch y (height)
1641 //sdci[9]=char
1642 //sdci[10]=opacity
1643
1644 18543 int32_t x=sdci[2]/10000;
1645 18543 int32_t y=sdci[3]/10000;
1646 18543 int32_t font_index=sdci[4]/10000;
1647 18543 int32_t color=sdci[5]/10000;
1648 18543 int32_t bg_color=sdci[6]/10000; //-1 = transparent
1649 18543 int32_t w=sdci[7]/10000;
1650 18543 int32_t h=sdci[8]/10000;
1651 18543 char glyph=char(sdci[9]/10000);
1652 18543 int32_t opacity=sdci[10]/10000;
1653
1654 //safe check
1655
1/2
✓ Branch 0 taken 18543 times.
✗ Branch 1 not taken.
18543 if(bg_color < -1) bg_color = -1;
1656
1657
1/2
✓ Branch 0 taken 18543 times.
✗ Branch 1 not taken.
18543 if(w>512) w=512; //w=vbound(w,0,512);
1658
1659
1/2
✓ Branch 0 taken 18543 times.
✗ Branch 1 not taken.
18543 if(h>512) h=512; //h=vbound(h,0,512);
1660
1661 //undone
1662
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 18543 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
18543 if(w>0&&h>0)//stretch the character
1663 {
1664 BITMAP *pbmp = script_drawing_commands.GetSmallTextureBitmap(1,1);
1665
1666 if(opacity < 128)
1667 {
1668 if(w>128||h>128)
1669 {
1670 clear_bitmap(prim_bmp);
1671
1672 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1673 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
1674 draw_trans_sprite(bmp, prim_bmp, x+xoffset, y+yoffset);
1675 }
1676 else //this is faster
1677 {
1678 BITMAP *pbmp2 = script_drawing_commands.AquireSubBitmap(w,h);
1679
1680 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1681 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
1682 draw_trans_sprite(bmp, pbmp2, x+xoffset, y+yoffset);
1683
1684 script_drawing_commands.ReleaseSubBitmap(pbmp2);
1685 }
1686 }
1687 else // no opacity
1688 {
1689 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1690 stretch_sprite(bmp, pbmp, x+xoffset, y+yoffset, w, h);
1691 }
1692
1693 }
1694 else //no stretch
1695 {
1696
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18543 times.
18543 if(opacity < 128)
1697 {
1698 BITMAP *pbmp = create_sub_bitmap(prim_bmp,0,0,16,16);
1699 clear_bitmap(pbmp);
1700
1701 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1702 draw_trans_sprite(bmp, pbmp, x+xoffset, y+yoffset);
1703
1704 destroy_bitmap(pbmp);
1705 }
1706 else // no opacity
1707 {
1708 18543 textprintf_ex(bmp, get_zc_font(font_index), x+xoffset, y+yoffset, color, bg_color, "%c", glyph);
1709 }
1710 }
1711 18543 }
1712
1713 else //2.53.0 fixed version and later.
1714 {
1715
1716 //sdci[1]=layer
1717 //sdci[2]=x
1718 //sdci[3]=y
1719 //sdci[4]=font
1720 //sdci[5]=color
1721 //sdci[6]=bg color
1722 //sdci[7]=strech x (width)
1723 //sdci[8]=stretch y (height)
1724 //sdci[9]=char
1725 //sdci[10]=opacity
1726
1727 945302 int32_t x=sdci[2]/10000;
1728 945302 int32_t y=sdci[3]/10000;
1729 945302 int32_t font_index=sdci[4]/10000;
1730 945302 int32_t color=sdci[5]/10000;
1731 945302 int32_t bg_color=sdci[6]/10000; //-1 = transparent
1732 945302 int32_t w=sdci[7]/10000;
1733 945302 int32_t h=sdci[8]/10000;
1734 945302 char glyph=char(sdci[9]/10000);
1735 945302 int32_t opacity=sdci[10]/10000;
1736
1737 //safe check
1738
1/2
✓ Branch 0 taken 945302 times.
✗ Branch 1 not taken.
945302 if(bg_color < -1) bg_color = -1;
1739
1740
1/2
✓ Branch 0 taken 945302 times.
✗ Branch 1 not taken.
945302 if(w>512) w=512; //w=vbound(w,0,512);
1741
1742
1/2
✓ Branch 0 taken 945302 times.
✗ Branch 1 not taken.
945302 if(h>512) h=512; //h=vbound(h,0,512);
1743
1744 //undone
1745
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 945302 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
945302 if(w>0&&h>0)//stretch the character
1746 {
1747 BITMAP *pbmp = script_drawing_commands.GetSmallTextureBitmap(1,1);
1748
1749 if(opacity < 128)
1750 {
1751 if(w>128||h>128)
1752 {
1753 clear_bitmap(prim_bmp);
1754
1755 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1756 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
1757 draw_trans_sprite(bmp, prim_bmp, x+xoffset, y+yoffset);
1758 }
1759 else //this is faster
1760 {
1761 BITMAP *pbmp2 = script_drawing_commands.AquireSubBitmap(w,h);
1762
1763 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1764 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
1765 draw_trans_sprite(bmp, pbmp2, x+xoffset, y+yoffset);
1766
1767 script_drawing_commands.ReleaseSubBitmap(pbmp2);
1768 }
1769 }
1770 else // no opacity
1771 {
1772 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1773 stretch_sprite(bmp, pbmp, x+xoffset, y+yoffset, w, h);
1774 }
1775
1776 }
1777 else //no stretch
1778 {
1779
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 945302 times.
945302 if(opacity < 128)
1780 {
1781 BITMAP *pbmp = create_sub_bitmap(prim_bmp,0,0,16,16);
1782 clear_bitmap(pbmp);
1783
1784 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1785 draw_trans_sprite(bmp, pbmp, x+xoffset, y+yoffset);
1786
1787 destroy_bitmap(pbmp);
1788 }
1789 else // no opacity
1790 {
1791 945302 textprintf_ex(bmp, get_zc_font(font_index), x+xoffset, y+yoffset, color, bg_color, "%c", glyph);
1792 }
1793 }
1794
1795 }
1796
1797 963845 }
1798
1799
1800 161253 void do_drawintr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1801 {
1802 //broken 2.50.2 and earlier drawinteger()
1803
2/2
✓ Branch 0 taken 72655 times.
✓ Branch 1 taken 88598 times.
161253 if ( get_qr(qr_BROKENCHARINTDRAWING) )
1804 {
1805 //sdci[1]=layer
1806 //sdci[2]=x
1807 //sdci[3]=y
1808 //sdci[4]=font
1809 //sdci[5]=color
1810 //sdci[6]=bg color
1811 //sdci[7]=strech x (width)
1812 //sdci[8]=stretch y (height)
1813 //sdci[9]=integer
1814 //sdci[10]=num decimal places
1815 //sdci[11]=opacity
1816
1817 72655 int32_t x=sdci[2]/10000;
1818 72655 int32_t y=sdci[3]/10000;
1819 72655 int32_t font_index=sdci[4]/10000;
1820 72655 int32_t color=sdci[5]/10000;
1821 72655 int32_t bg_color=sdci[6]/10000; //-1 = transparent
1822 72655 int32_t w=sdci[7]/10000;
1823 72655 int32_t h=sdci[8]/10000;
1824 72655 int32_t decplace=sdci[10]/10000;
1825 72655 int32_t opacity=sdci[11]/10000;
1826
1827 //safe check
1828
1/2
✓ Branch 0 taken 72655 times.
✗ Branch 1 not taken.
72655 if(bg_color < -1) bg_color = -1;
1829
1830
1/2
✓ Branch 0 taken 72655 times.
✗ Branch 1 not taken.
72655 if(w>512) w=512; //w=vbound(w,0,512);
1831
1832
1/2
✓ Branch 0 taken 72655 times.
✗ Branch 1 not taken.
72655 if(h>512) h=512; //h=vbound(h,0,512);
1833
1834 char numbuf[15];
1835
1836
1/6
✓ Branch 0 taken 72655 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
72655 switch(decplace)
1837 {
1838 default:
1839 case 0:
1840 72655 sprintf(numbuf,"%d",(sdci[9]/10000)); //For some reason, static casting for zero decimal places was
1841 72655 break; //reducing the value by -1, so 8.000 printed as '7'. -Z
1842
1843 case 1:
1844 //sprintf(numbuf,"%.01f",number);
1845 sprintf(numbuf,"%.01f",(static_cast<float>(sdci[9])/10000.0f)); //Would this be slower?
1846 break;
1847
1848 case 2:
1849 //sprintf(numbuf,"%.02f",number);
1850 sprintf(numbuf,"%.02f",(static_cast<float>(sdci[9])/10000.0f));
1851 break;
1852
1853 case 3:
1854 //sprintf(numbuf,"%.03f",number);
1855 sprintf(numbuf,"%.03f",(static_cast<float>(sdci[9])/10000.0f));
1856 break;
1857
1858 case 4:
1859 //sprintf(numbuf,"%.04f",number);
1860 sprintf(numbuf,"%.04f",(static_cast<float>(sdci[9])/10000.0f));
1861 break;
1862 }
1863
1864
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 72655 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
72655 if(w>0&&h>0)//stretch
1865 {
1866 BITMAP *pbmp = script_drawing_commands.GetSmallTextureBitmap(1,1);
1867
1868 if(opacity < 128)
1869 {
1870 if(w>128||h>128)
1871 {
1872 clear_bitmap(prim_bmp);
1873
1874 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
1875 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
1876 draw_trans_sprite(bmp, prim_bmp, x+xoffset, y+yoffset);
1877 }
1878 else
1879 {
1880 BITMAP *pbmp2 = create_sub_bitmap(prim_bmp,0,0,w,h);
1881 clear_bitmap(pbmp2);
1882
1883 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
1884 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
1885 draw_trans_sprite(bmp, pbmp2, x+xoffset, y+yoffset);
1886
1887 destroy_bitmap(pbmp2);
1888 }
1889 }
1890 else // no opacity
1891 {
1892 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
1893 stretch_sprite(bmp, pbmp, x+xoffset, y+yoffset, w, h);
1894 }
1895
1896 }
1897 else //no stretch
1898 {
1899
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72655 times.
72655 if(opacity < 128)
1900 {
1901 BITMAP *pbmp = create_sub_bitmap(prim_bmp,0,0,16,16);
1902 clear_bitmap(pbmp);
1903
1904 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
1905 draw_trans_sprite(bmp, pbmp, x+xoffset, y+yoffset);
1906
1907 destroy_bitmap(pbmp);
1908 }
1909 else // no opacity
1910 {
1911 72655 textout_ex(bmp, get_zc_font(font_index), numbuf, x+xoffset, y+yoffset, color, bg_color);
1912 }
1913 }
1914
1915 72655 }
1916
1917 else //2.53.0 fixed version and later.
1918 {
1919 //sdci[1]=layer
1920 //sdci[2]=x
1921 //sdci[3]=y
1922 //sdci[4]=font
1923 //sdci[5]=color
1924 //sdci[6]=bg color
1925 //sdci[7]=strech x (width)
1926 //sdci[8]=stretch y (height)
1927 //sdci[9]=integer
1928 //sdci[10]=num decimal places
1929 //sdci[11]=opacity
1930
1931 88598 int32_t x=sdci[2]/10000;
1932 88598 int32_t y=sdci[3]/10000;
1933 88598 int32_t font_index=sdci[4]/10000;
1934 88598 int32_t color=sdci[5]/10000;
1935 88598 int32_t bg_color=sdci[6]/10000; //-1 = transparent
1936 88598 int32_t w=sdci[7]/10000;
1937 88598 int32_t h=sdci[8]/10000;
1938 88598 int32_t decplace=sdci[10]/10000;
1939 88598 int32_t opacity=sdci[11]/10000;
1940
1941 //safe check
1942
1/2
✓ Branch 0 taken 88598 times.
✗ Branch 1 not taken.
88598 if(bg_color < -1) bg_color = -1;
1943
1944
1/2
✓ Branch 0 taken 88598 times.
✗ Branch 1 not taken.
88598 if(w>512) w=512; //w=vbound(w,0,512);
1945
1946
1/2
✓ Branch 0 taken 88598 times.
✗ Branch 1 not taken.
88598 if(h>512) h=512; //h=vbound(h,0,512);
1947
1948 char numbuf[15];
1949
1950
1/6
✓ Branch 0 taken 88598 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
88598 switch(decplace)
1951 {
1952 default:
1953 case 0:
1954 88598 sprintf(numbuf,"%d",(sdci[9]/10000)); //For some reason, static casting for zero decimal places was
1955 88598 break; //reducing the value by -1, so 8.000 printed as '7'. -Z
1956
1957 case 1:
1958 //sprintf(numbuf,"%.01f",number);
1959 sprintf(numbuf,"%.01f",(static_cast<float>(sdci[9])/10000.0f)); //Would this be slower?
1960 break;
1961
1962 case 2:
1963 //sprintf(numbuf,"%.02f",number);
1964 sprintf(numbuf,"%.02f",(static_cast<float>(sdci[9])/10000.0f));
1965 break;
1966
1967 case 3:
1968 //sprintf(numbuf,"%.03f",number);
1969 sprintf(numbuf,"%.03f",(static_cast<float>(sdci[9])/10000.0f));
1970 break;
1971
1972 case 4:
1973 //sprintf(numbuf,"%.04f",number);
1974 sprintf(numbuf,"%.04f",(static_cast<float>(sdci[9])/10000.0f));
1975 break;
1976 }
1977
1978 //FONT* font=get_zc_font(sdci[4]/10000);
1979
1980
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 88598 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
88598 if(w>0&&h>0)//stretch
1981 {
1982 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, text_length(get_zc_font(font_index), numbuf)+1, text_height(get_zc_font(font_index)));
1983 clear_bitmap(pbmp);
1984 //script_drawing_commands.GetSmallTextureBitmap(1,1);
1985
1986 if(opacity < 128)
1987 {
1988 if(w>128||h>128)
1989 {
1990 clear_bitmap(prim_bmp);
1991
1992 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
1993 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
1994 draw_trans_sprite(bmp, prim_bmp, x+xoffset, y+yoffset);
1995 }
1996 else
1997 {
1998 BITMAP *pbmp2 = create_sub_bitmap(prim_bmp,0,0,w,h);
1999 clear_bitmap(pbmp2);
2000
2001 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
2002 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
2003 draw_trans_sprite(bmp, pbmp2, x+xoffset, y+yoffset);
2004
2005 destroy_bitmap(pbmp2);
2006 }
2007 }
2008 else // no opacity
2009 {
2010 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
2011 stretch_sprite(bmp, pbmp, x+xoffset, y+yoffset, w, h);
2012 }
2013
2014 }
2015 else //no stretch
2016 {
2017
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 88598 times.
88598 if(opacity < 128)
2018 {
2019 FONT* font = get_zc_font(font_index);
2020 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, text_length(font, numbuf), text_height(font));
2021 clear_bitmap(pbmp);
2022
2023 textout_ex(pbmp, font, numbuf, 0, 0, color, bg_color);
2024 draw_trans_sprite(bmp, pbmp, x+xoffset, y+yoffset);
2025
2026 destroy_bitmap(pbmp);
2027 }
2028 else // no opacity
2029 {
2030 88598 textout_ex(bmp, get_zc_font(font_index), numbuf, x+xoffset, y+yoffset, color, bg_color);
2031 }
2032 }
2033 }
2034 161253 }
2035
2036
2037 1587964 void do_drawstringr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
2038 {
2039 //sdci[1]=layer
2040 //sdci[2]=x
2041 //sdci[3]=y
2042 //sdci[4]=font
2043 //sdci[5]=color
2044 //sdci[6]=bg color
2045 //sdci[7]=format_option
2046 //sdci[8]=string
2047 //sdci[9]=opacity
2048
2049 1587964 std::string* str = (std::string*)script_drawing_commands[i].GetPtr();
2050
2051
1/2
✓ Branch 0 taken 1587964 times.
✗ Branch 1 not taken.
1587964 if(!str)
2052 {
2053 al_trace("String pointer is null! Internal error. \n");
2054 return;
2055 }
2056
2057 1587964 int32_t x=sdci[2]/10000;
2058 1587964 int32_t y=sdci[3]/10000;
2059 1587964 FONT* font=get_zc_font(sdci[4]/10000);
2060 1587964 int32_t color=sdci[5]/10000;
2061 1587964 int32_t bg_color=sdci[6]/10000; //-1 = transparent
2062 1587964 int32_t format_type=sdci[7]/10000;
2063 1587964 int32_t opacity=sdci[9]/10000;
2064 //sdci[8] not needed :)
2065
2066 //safe check
2067
1/2
✓ Branch 0 taken 1587964 times.
✗ Branch 1 not taken.
1587964 if(bg_color < -1) bg_color = -1;
2068
2069
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1587964 times.
1587964 if(opacity < 128)
2070 {
2071 int32_t width=zc_min(text_length(font, str->c_str()), 512);
2072 if (width < 1) return; //SANITY -Em
2073 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, width, text_height(font));
2074 clear_bitmap(pbmp);
2075 textout_ex(pbmp, font, str->c_str(), 0, 0, color, bg_color);
2076 if(format_type == 2) // right-sided text
2077 x-=width;
2078 else if(format_type == 1) // centered text
2079 x-=width/2;
2080 draw_trans_sprite(bmp, pbmp, x+xoffset, y+yoffset);
2081 destroy_bitmap(pbmp);
2082 }
2083 else // no opacity
2084 {
2085
2/2
✓ Branch 0 taken 14345 times.
✓ Branch 1 taken 1573619 times.
1587964 if(format_type == 2) // right-sided text
2086 {
2087 14345 textout_right_ex(bmp, font, str->c_str(), x+xoffset, y+yoffset, color, bg_color);
2088 14345 }
2089
2/2
✓ Branch 0 taken 725712 times.
✓ Branch 1 taken 847907 times.
1573619 else if(format_type == 1) // centered text
2090 {
2091 725712 textout_centre_ex(bmp, font, str->c_str(), x+xoffset, y+yoffset, color, bg_color);
2092 725712 }
2093 else // standard left-sided text
2094 {
2095 847907 textout_ex(bmp, font, str->c_str(), x+xoffset, y+yoffset, color, bg_color);
2096 }
2097 }
2098 1587964 }
2099
2100 163717 void do_drawstringr2(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
2101 {
2102 //sdci[1]=layer
2103 //sdci[2]=x
2104 //sdci[3]=y
2105 //sdci[4]=font
2106 //sdci[5]=color
2107 //sdci[6]=bg color
2108 //sdci[7]=format_option
2109 //sdci[8]=string
2110 //sdci[9]=opacity
2111 //sdci[10]=shadowtype
2112 //sdci[11]=shadow_color
2113
2114 163717 std::string* str = (std::string*)script_drawing_commands[i].GetPtr();
2115
2116
1/2
✓ Branch 0 taken 163717 times.
✗ Branch 1 not taken.
163717 if(!str)
2117 {
2118 al_trace("String pointer is null! Internal error. \n");
2119 return;
2120 }
2121
2122 163717 int32_t x=sdci[2]/10000;
2123 163717 int32_t y=sdci[3]/10000;
2124 163717 FONT* font=get_zc_font(sdci[4]/10000);
2125 163717 int32_t color=sdci[5]/10000;
2126 163717 int32_t bg_color=sdci[6]/10000; //-1 = transparent
2127 163717 int32_t format_type=sdci[7]/10000;
2128 163717 int32_t opacity=sdci[9]/10000;
2129 163717 int32_t textstyle = sdci[10]/10000;
2130 163717 int32_t shadow_color = sdci[11]/10000;
2131 //sdci[8] not needed :)
2132
2133 //safe check
2134
1/2
✓ Branch 0 taken 163717 times.
✗ Branch 1 not taken.
163717 if(bg_color < -1) bg_color = -1;
2135
2136
2/2
✓ Branch 0 taken 740 times.
✓ Branch 1 taken 162977 times.
163717 if(opacity < 128)
2137 {
2138
1/2
✓ Branch 0 taken 740 times.
✗ Branch 1 not taken.
740 int32_t width=zc_min(text_length(font, str->c_str()), 512);
2139
1/2
✓ Branch 0 taken 740 times.
✗ Branch 1 not taken.
740 if (width < 1) return; //SANITY -Em
2140 740 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, width, text_height(font));
2141 740 clear_bitmap(pbmp);
2142 740 textout_styled_aligned_ex(pbmp, font, str->c_str(), 0, 0, textstyle, sstaLEFT, color, shadow_color, bg_color);
2143 740 textout_ex(pbmp, font, str->c_str(), 0, 0, color, bg_color);
2144
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 740 times.
740 if(format_type == 2) // right-sided text
2145 x-=width;
2146
1/2
✓ Branch 0 taken 740 times.
✗ Branch 1 not taken.
740 else if(format_type == 1) // centered text
2147 740 x-=width/2;
2148 740 draw_trans_sprite(bmp, pbmp, x+xoffset, y+yoffset);
2149 740 destroy_bitmap(pbmp);
2150 740 }
2151 else // no opacity
2152 {
2153 162977 textout_styled_aligned_ex(bmp, font, str->c_str(), x+xoffset, y+yoffset, textstyle, format_type, color, shadow_color, bg_color);
2154 }
2155 163717 }
2156
2157
2158 9266 void do_drawquadr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
2159 {
2160 //sdci[1]=layer
2161 //sdci[2]=x1
2162 //sdci[3]=y1
2163 //sdci[4]=x2
2164 //sdci[5]=y2
2165 //sdci[6]=x3
2166 //sdci[7]=y3
2167 //sdci[8]=x4
2168 //sdci[9]=y4
2169 //sdci[10]=width
2170 //sdci[11]=height
2171 //sdci[12]=cset
2172 //sdci[13]=flip
2173 //sdci[14]=tile/combo
2174 //sdci[15]=polytype
2175
2176 9266 int32_t x1 = sdci[2]/10000;
2177 9266 int32_t y1 = sdci[3]/10000;
2178 9266 int32_t x2 = sdci[4]/10000;
2179 9266 int32_t y2 = sdci[5]/10000;
2180 9266 int32_t x3 = sdci[6]/10000;
2181 9266 int32_t y3 = sdci[7]/10000;
2182 9266 int32_t x4 = sdci[8]/10000;
2183 9266 int32_t y4 = sdci[9]/10000;
2184 9266 int32_t w = sdci[10]/10000;
2185 9266 int32_t h = sdci[11]/10000;
2186 9266 int32_t color = sdci[12]/10000;
2187 9266 int32_t flip=(sdci[13]/10000)&3;
2188 9266 int32_t tile = sdci[14]/10000;
2189 9266 int32_t polytype = sdci[15]/10000;
2190
2191 //todo: finish palette shading
2192 /*
2193 POLYTYPE_FLAT
2194 POLYTYPE_GCOL
2195 POLYTYPE_GRGB
2196 POLYTYPE_ATEX
2197 POLYTYPE_PTEX
2198 POLYTYPE_ATEX_MASK
2199 POLYTYPE_PTEX_MASK
2200 POLYTYPE_ATEX_LIT
2201 POLYTYPE_PTEX_LIT
2202 POLYTYPE_ATEX_MASK_LIT
2203 POLYTYPE_PTEX_MASK_LIT
2204 POLYTYPE_ATEX_TRANS
2205 POLYTYPE_PTEX_TRANS
2206 POLYTYPE_ATEX_MASK_TRANS
2207 POLYTYPE_PTEX_MASK_TRANS
2208 */
2209 9266 polytype = vbound(polytype, 0, 14);
2210
2211
2/4
✓ Branch 0 taken 9266 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9266 times.
9266 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
2212 {
2213 Z_message("Quad() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
2214 return; //non power of two error
2215 }
2216
2217 9266 int32_t tex_width = w*16;
2218 9266 int32_t tex_height = h*16;
2219
2220 BITMAP *tex;
2221
2222 9266 bool mustDestroyBmp = false;
2223
2224
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9266 times.
9266 if ( tile > 65519 ) tex = zscriptDrawingRenderTarget->GetBitmapPtr(tile - 65519);
2225 9266 else tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
2226
2227
1/2
✓ Branch 0 taken 9266 times.
✗ Branch 1 not taken.
9266 if(!tex)
2228 {
2229 mustDestroyBmp = true;
2230 tex = create_bitmap_ex(8, tex_width, tex_height);
2231 clear_bitmap(tex);
2232 }
2233
2234 int32_t col[4];
2235 /*
2236 if( color < 0 )
2237 {
2238 col[0]=draw_container.color_buffer[0];
2239 col[1]=draw_container.color_buffer[1];
2240 col[2]=draw_container.color_buffer[2];
2241 col[3]=draw_container.color_buffer[3];
2242 }
2243 else */
2244 {
2245 9266 col[0]=col[1]=col[2]=col[3]=color;
2246 }
2247
2248
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9266 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9266 if(tile > 0 && tile <= 65519) // TILE
2249 {
2250 TileHelper::OverTile(tex, tile, 0, 0, w, h, color, flip);
2251 }
2252
2253
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9266 times.
9266 if ( tile < 0 ) // COMBO
2254 {
2255 9266 auto& c = GET_DRAWING_COMBO(vbound(abs(tile), 0, 0xffff));
2256 9266 const int32_t tiletodraw = combo_tile(c, x1, y1);
2257 9266 flip = flip ^ c.flip;
2258
2259 9266 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, color, flip);
2260 9266 }
2261
2262 9266 V3D_f V1 = { static_cast<float>(x1+xoffset), static_cast<float>(y1+yoffset), 0, 0, 0, col[0] };
2263 9266 V3D_f V2 = { static_cast<float>(x2+xoffset), static_cast<float>(y2+yoffset), 0, 0, static_cast<float>(tex_height), col[1] };
2264 9266 V3D_f V3 = { static_cast<float>(x3+xoffset), static_cast<float>(y3+yoffset), 0, static_cast<float>(tex_width), static_cast<float>(tex_height), col[2] };
2265 9266 V3D_f V4 = { static_cast<float>(x4+xoffset), static_cast<float>(y4+yoffset), 0, static_cast<float>(tex_width), 0, col[3] };
2266
2267 9266 quad3d_f(bmp, polytype, tex, &V1, &V2, &V3, &V4);
2268
2269
1/2
✓ Branch 0 taken 9266 times.
✗ Branch 1 not taken.
9266 if(mustDestroyBmp)
2270 destroy_bitmap(tex);
2271
2272 9266 }
2273
2274
2275 void do_drawtriangler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
2276 {
2277 //sdci[1]=layer
2278 //sdci[2]=x1
2279 //sdci[3]=y1
2280 //sdci[4]=x2
2281 //sdci[5]=y2
2282 //sdci[6]=x3
2283 //sdci[7]=y3
2284 //sdci[8]=width
2285 //sdci[9]=height
2286 //sdci[10]=cset
2287 //sdci[11]=flip
2288 //sdci[12]=tile/combo
2289 //sdci[13]=polytype
2290
2291 int32_t x1 = sdci[2]/10000;
2292 int32_t y1 = sdci[3]/10000;
2293 int32_t x2 = sdci[4]/10000;
2294 int32_t y2 = sdci[5]/10000;
2295 int32_t x3 = sdci[6]/10000;
2296 int32_t y3 = sdci[7]/10000;
2297 int32_t w = sdci[8]/10000;
2298 int32_t h = sdci[9]/10000;
2299 int32_t color = sdci[10]/10000;
2300 int32_t flip=(sdci[11]/10000)&3;
2301 int32_t tile = sdci[12]/10000;
2302 int32_t polytype = sdci[13]/10000;
2303
2304 polytype = vbound(polytype, 0, 14);
2305
2306 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
2307 {
2308 Z_message("Quad() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
2309 return; //non power of two error
2310 }
2311
2312 int32_t tex_width = w*16;
2313 int32_t tex_height = h*16;
2314
2315 bool mustDestroyBmp = false;
2316 BITMAP *tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
2317
2318 if(!tex)
2319 {
2320 mustDestroyBmp = true;
2321 tex = create_bitmap_ex(8, tex_width, tex_height);
2322 clear_bitmap(tex);
2323 }
2324
2325 int32_t col[3];
2326 /*
2327 if( color < 0 )
2328 {
2329 col[0]=draw_container.color_buffer[0];
2330 col[1]=draw_container.color_buffer[1];
2331 col[2]=draw_container.color_buffer[2];
2332 }
2333 else */
2334 {
2335 col[0]=col[1]=col[2]=color;
2336 }
2337
2338 if(tile > 0) // TILE
2339 {
2340 TileHelper::OverTile(tex, tile, 0, 0, w, h, color, flip);
2341 }
2342 else // COMBO
2343 {
2344 auto& c = GET_DRAWING_COMBO(vbound(abs(tile), 0, 0xffff));
2345 const int32_t tiletodraw = combo_tile(c, x1, y1);
2346 flip = flip ^ c.flip;
2347
2348 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, color, flip);
2349 }
2350
2351 V3D_f V1 = { static_cast<float>(x1+xoffset), static_cast<float>(y1+yoffset), 0, 0, 0, col[0] };
2352 V3D_f V2 = { static_cast<float>(x2+xoffset), static_cast<float>(y2+yoffset), 0, 0, static_cast<float>(tex_height), col[1] };
2353 V3D_f V3 = { static_cast<float>(x3+xoffset), static_cast<float>(y3+yoffset), 0, static_cast<float>(tex_width), static_cast<float>(tex_height), col[2] };
2354
2355
2356 triangle3d_f(bmp, polytype, tex, &V1, &V2, &V3);
2357
2358 if(mustDestroyBmp)
2359 destroy_bitmap(tex);
2360 }
2361
2362
2363 933060 void do_drawbitmapr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
2364 {
2365 //sdci[1]=layer
2366 //sdci[2]=bitmap
2367 //sdci[3]=sourcex
2368 //sdci[4]=sourcey
2369 //sdci[5]=sourcew
2370 //sdci[6]=sourceh
2371 //sdci[7]=destx
2372 //sdci[8]=desty
2373 //sdci[9]=destw
2374 //sdci[10]=desth
2375 //sdci[11]=rotation
2376 //sdci[12]=mask
2377
2378 933060 int32_t bitmapIndex = sdci[2]/10000;
2379 933060 int32_t sx = sdci[3]/10000;
2380 933060 int32_t sy = sdci[4]/10000;
2381 933060 int32_t sw = sdci[5]/10000;
2382 933060 int32_t sh = sdci[6]/10000;
2383 933060 int32_t dx = sdci[7]/10000;
2384 933060 int32_t dy = sdci[8]/10000;
2385 933060 int32_t dw = sdci[9]/10000;
2386 933060 int32_t dh = sdci[10]/10000;
2387 933060 float rot = sdci[11]/10000;
2388 933060 bool masked = (sdci[12] != 0);
2389
2390 //bugfix
2391 933060 sx = vbound(sx, 0, 512);
2392 933060 sy = vbound(sy, 0, 512);
2393 933060 sw = vbound(sw, 0, 512 - sx); //keep the w/h within range as well
2394 933060 sh = vbound(sh, 0, 512 - sy);
2395
2396
2397
2/4
✓ Branch 0 taken 933060 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 933060 times.
933060 if(sx >= ZScriptDrawingRenderTarget::BitmapWidth || sy >= ZScriptDrawingRenderTarget::BitmapHeight)
2398 return;
2399
2400
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 933060 times.
933060 bool stretched = (sw != dw || sh != dh);
2401
2402 933060 BITMAP *sourceBitmap = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex);
2403
2404
1/2
✓ Branch 0 taken 933060 times.
✗ Branch 1 not taken.
933060 if(!sourceBitmap)
2405 {
2406 Z_message("Warning: Screen->DrawBitmap(%d) contains invalid data or is not initialized.\n", bitmapIndex);
2407 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
2408 return;
2409 }
2410
2411 933060 BITMAP* subBmp = 0;
2412
2413
1/2
✓ Branch 0 taken 933060 times.
✗ Branch 1 not taken.
933060 if(rot != 0)
2414 {
2415 subBmp = script_drawing_commands.AquireSubBitmap(dw, dh);
2416
2417 if(!subBmp)
2418 {
2419 Z_scripterrlog("DrawBitmap() failed to create a sub-bitmap to use for %s. Aborting.\n", "rotation");
2420 return;
2421 }
2422 }
2423
2424
2425 933060 dx = dx + xoffset;
2426 933060 dy = dy + yoffset;
2427
2428
2/2
✓ Branch 0 taken 240 times.
✓ Branch 1 taken 932820 times.
933060 if(stretched)
2429 {
2430
1/2
✓ Branch 0 taken 240 times.
✗ Branch 1 not taken.
240 if(masked)
2431 {
2432
1/2
✓ Branch 0 taken 240 times.
✗ Branch 1 not taken.
240 if(rot != 0)
2433 {
2434 //if ( rot == 4096 ) { //translucent
2435 // masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2436 // //rotate_sprite_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2437 // draw_trans_sprite(bmp, subBmp, dx, dy);
2438 // //draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, 0);
2439
2440
2441 // }
2442 //else {
2443 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2444 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2445 //rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2446 //
2447
2448 // }
2449 }
2450 else
2451 240 masked_stretch_blit(sourceBitmap, bmp, sx, sy, sw, sh, dx, dy, dw, dh);
2452 240 }
2453 else
2454 {
2455 if(rot != 0)
2456 {
2457 //if ( rot == 4096 ) { //translucent
2458 // stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2459 // draw_trans_sprite(bmp, subBmp, dx, dy);
2460 // }
2461 //else {
2462 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2463 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2464 // }
2465 }
2466 else
2467 stretch_blit(sourceBitmap, bmp, sx, sy, sw, sh, dx, dy, dw, dh);
2468 }
2469 240 }
2470 else
2471 {
2472
2/2
✓ Branch 0 taken 928098 times.
✓ Branch 1 taken 4722 times.
932820 if(masked)
2473 {
2474
1/2
✓ Branch 0 taken 928098 times.
✗ Branch 1 not taken.
928098 if(rot != 0)
2475 {
2476 //if ( rot == 4096 ) {//translucent
2477 // masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
2478 //rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2479
2480 //masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2481 //rotate_sprite_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2482 // draw_trans_sprite(bmp, subBmp, dx, dy);
2483 // }
2484 //else {
2485 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
2486 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2487 // }
2488 }
2489 else
2490 928098 masked_blit(sourceBitmap, bmp, sx, sy, dx, dy, dw, dh);
2491 928098 }
2492 else
2493 {
2494
1/2
✓ Branch 0 taken 4722 times.
✗ Branch 1 not taken.
4722 if(rot != 0)
2495 {
2496 //if ( rot == 4096 ) { //translucent
2497 // blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
2498 // draw_trans_sprite(bmp, subBmp, dx, dy);
2499 // }
2500 //else {
2501 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
2502 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2503 // }
2504 }
2505 else
2506 4722 blit(sourceBitmap, bmp, sx, sy, dx, dy, dw, dh);
2507 }
2508 }
2509
2510 //cleanup
2511
1/2
✓ Branch 0 taken 933060 times.
✗ Branch 1 not taken.
933060 if(subBmp)
2512 {
2513 script_drawing_commands.ReleaseSubBitmap(subBmp);
2514 }
2515 933060 }
2516
2517
2518 //Draw]()
2519 void do_drawbitmapexr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
2520 {
2521 /*
2522 //sdci[1]=layer
2523 //sdci[2]=bitmap
2524 //sdci[3]=sourcex
2525 //sdci[4]=sourcey
2526 //sdci[5]=sourcew
2527 //sdci[6]=sourceh
2528 //sdci[7]=destx
2529 //sdci[8]=desty
2530 //sdci[9]=destw
2531 //sdci[10]=desth
2532 //sdci[11]=rotation/angle
2533 //scdi[12] = pivot cx
2534 //sdci[13] = pivot cy
2535 //scdi[14] = effect flags
2536
2537
2538 const int32_t BITDX_NORMAL = 0;
2539 const int32_t BITDX_TRANS = 1; //Translucent
2540 const int32_t BITDX_PIVOT = 2; //THe sprite will rotate at a specific point, instead of its center.
2541 const int32_t BITDX_HFLIP = 4; //Horizontal Flip
2542 const int32_t BITDX_VFLIP = 8; //Vertical Flip.
2543 //Note: Some modes cannot be combined. if a combination is not supported, an error
2544 // detailing this will be shown in allegro.log.
2545
2546 //scdi[15] = litcolour
2547 //The allegro docs are wrong. The params are: rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
2548 /not rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2549
2550 //sdci[16]=mask
2551
2552 */
2553
2554 int32_t bitmapIndex = sdci[2]/10000;
2555 int32_t sx = sdci[3]/10000;
2556 int32_t sy = sdci[4]/10000;
2557 int32_t sw = sdci[5]/10000;
2558 int32_t sh = sdci[6]/10000;
2559 int32_t dx = sdci[7]/10000;
2560 int32_t dy = sdci[8]/10000;
2561 int32_t dw = sdci[9]/10000;
2562 int32_t dh = sdci[10]/10000;
2563 float rot = sdci[11]/10000;
2564 int32_t cx = sdci[12]/10000;
2565 int32_t cy = sdci[13]/10000;
2566 int32_t mode = sdci[14]/10000;
2567 int32_t litcolour = sdci[15]/10000;
2568 bool masked = (sdci[16] != 0);
2569
2570
2571
2572 //bugfix
2573 sx = vbound(sx, 0, 512);
2574 sy = vbound(sy, 0, 512);
2575 sw = vbound(sw, 0, 512 - sx); //keep the w/h within range as well
2576 sh = vbound(sh, 0, 512 - sy);
2577
2578
2579 if(sx >= ZScriptDrawingRenderTarget::BitmapWidth || sy >= ZScriptDrawingRenderTarget::BitmapHeight)
2580 return;
2581
2582 bool stretched = (sw != dw || sh != dh);
2583
2584 BITMAP *sourceBitmap = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex);
2585
2586 if(!sourceBitmap)
2587 {
2588 Z_message("Warning: Screen->DrawBitmap(%d) contains invalid data or is not initialized.\n", bitmapIndex);
2589 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
2590 return;
2591 }
2592
2593 BITMAP* subBmp = 0;
2594
2595 /*
2596 if ( bitmapIndex == -1 ) {
2597 blit(bmp, sourceBitmap, sx, sy, 0, 0, dw, dh);
2598 }
2599 */
2600
2601 if(rot != 0 || mode != 0)
2602 {
2603 subBmp = script_drawing_commands.AquireSubBitmap(dw, dh);
2604
2605 if(!subBmp)
2606 {
2607 Z_scripterrlog("bitmap->Blit failed to create a sub-bitmap to use for %s. Aborting.\n", "rotation");
2608 return;
2609 }
2610 }
2611
2612
2613 dx = dx + xoffset;
2614 dy = dy + yoffset;
2615
2616 if(stretched)
2617 {
2618 if(masked) //stretched and masked
2619 {
2620 if ( rot == 0 ) //if not rotated
2621 {
2622 switch(mode)
2623 {
2624 case 1:
2625 //transparent
2626 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2627 draw_trans_sprite(bmp, subBmp, dx, dy);
2628 break;
2629
2630
2631 case 2:
2632 //pivot?
2633 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2634 pivot_sprite(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
2635 //Pivoting requires two more args
2636 break;
2637
2638 case 3:
2639 //pivot + trans
2640 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2641 pivot_sprite_trans(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
2642 break;
2643
2644 case 4:
2645 //flip v
2646 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2647 draw_sprite_v_flip(bmp, subBmp, dx, dy);
2648 break;
2649
2650 case 5:
2651 //trans + v flip
2652 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2653 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
2654 break;
2655
2656 case 6:
2657 //pivot + v flip
2658 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2659 pivot_sprite_v_flip(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
2660 break;
2661
2662 case 8:
2663 //vlip h
2664 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2665 draw_sprite_h_flip(bmp, subBmp, dx, dy);
2666 break;
2667
2668 case 9:
2669 //trans + h flip
2670 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2671 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
2672 break;
2673
2674 case 10:
2675 //flip H and pivot
2676 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
2677 //return error cannot pivot and h flip
2678 break;
2679
2680 case 12:
2681 //vh flip
2682 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2683 draw_sprite_vh_flip(bmp, subBmp, dx, dy);
2684 break;
2685
2686 case 13:
2687 //trans + vh flip
2688 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2689 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
2690 break;
2691
2692 case 14:
2693 //pivot and vh flip
2694 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
2695 //return error cannot both pivot and vh flip
2696 break;
2697
2698 case 16:
2699 //lit
2700 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2701 draw_lit_sprite(bmp, subBmp, dx, dy, litcolour);
2702 break;
2703
2704 case 18:
2705 //pivot, lit
2706 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2707 pivot_sprite_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
2708 break;
2709
2710 case 20:
2711 //lit + v flip
2712 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2713 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
2714 break;
2715
2716 case 22:
2717 //Pivot, vflip, lit
2718 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2719 pivot_sprite_v_flip_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
2720 break;
2721
2722 case 24:
2723 //lit + h flip
2724 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2725 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
2726 break;
2727
2728 case 26:
2729 //pivot + lit + hflip
2730 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
2731 //return error cannot pivot, lit, and flip
2732 break;
2733
2734 case 28:
2735 //lit + vh flip
2736 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2737 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
2738 break;
2739
2740 case 32: //gouraud
2741 //Probably not wort supporting.
2742 //masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2743 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
2744 break;
2745
2746 case 0:
2747 //no effect
2748 masked_stretch_blit(sourceBitmap, bmp, sx, sy, sw, sh, dx, dy, dw, dh);
2749 break;
2750
2751
2752 default:
2753 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
2754
2755
2756 }
2757 } //end if not rotated
2758
2759 if ( rot != 0 ) //if rotated
2760 {
2761 switch(mode)
2762 {
2763 case 1:
2764 //transparent
2765 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2766 rotate_sprite_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2767
2768 break;
2769
2770 case 2:
2771 //pivot?
2772 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
2773 //return an error, cannot both rotate and pivot
2774 break;
2775
2776 case 3:
2777 //pivot + trans
2778 //return an error, cannot both rotate and pivot
2779 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
2780 break;
2781
2782 case 4:
2783 //flip v
2784 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2785 rotate_sprite_v_flip(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2786 break;
2787
2788 case 5:
2789 //trans + v flip
2790 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2791 rotate_sprite_v_flip_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2792 break;
2793
2794 case 6:
2795 //pivot + v flip
2796 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
2797 //return an error, cannot both rotate and pivot
2798 break;
2799
2800 case 8:
2801 //flip h
2802 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
2803 //return an error, cannot both rotate and flip H
2804 break;
2805
2806 case 9:
2807 //trans + h flip
2808 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
2809 //return an error, cannot rotate and flip a trans sprite
2810 break;
2811
2812 case 10:
2813 //flip H and pivot
2814 //return error cannot pivot and h flip
2815 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
2816 break;
2817
2818 case 12:
2819 //vh flip
2820 //return an error, cannot rotate and VH flip a trans sprite
2821 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
2822 break;
2823
2824 case 13:
2825 //trans + vh flip
2826 //return an error, cannot rotate and VH flip a trans sprite
2827 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
2828 break;
2829
2830 case 14:
2831 //pivot and vh flip
2832 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
2833 //return error cannot both pivot and vh flip
2834 break;
2835
2836 case 16:
2837 //lit
2838 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2839 rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
2840 break;
2841
2842 case 18:
2843 //pivot, lit
2844 //return an error, cannot both rotate and pivot
2845 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
2846 break;
2847
2848 case 20:
2849 //lit + vflip
2850 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2851 rotate_sprite_v_flip_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
2852 break;
2853
2854 case 22:
2855 //Pivot, vflip, lit
2856 //return an error, cannot both rotate and pivot
2857 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
2858 break;
2859
2860 case 24:
2861 //lit + h flip
2862 //return an error, cannot both rotate and H flip
2863 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
2864 break;
2865
2866 case 26:
2867 //pivot + lit + hflip
2868 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
2869 //return error cannot pivot, lit, and flip
2870 break;
2871
2872 case 28:
2873 //lit + vh flip
2874 //return an error, cannot both rotate and VH flip
2875 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
2876 break;
2877
2878 case 32: //gouraud
2879 //Probably not wort supporting.
2880 //masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2881 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
2882 break;
2883
2884 case 0:
2885 //no effect.
2886 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2887 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2888 break;
2889
2890 default:
2891 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
2892
2893 }
2894 }
2895 } //end if stretched and masked
2896
2897 else //stretched, not masked
2898 {
2899 if ( rot == 0 ) //if not rotated
2900 {
2901 switch(mode) {
2902 case 1:
2903 //transparent
2904 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2905 draw_trans_sprite(bmp, subBmp, dx, dy);
2906 break;
2907
2908
2909 case 2:
2910 //pivot?
2911 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2912 pivot_sprite(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
2913 //Pivoting requires two more args
2914 break;
2915
2916 case 3:
2917 //pivot + trans
2918 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2919 pivot_sprite_trans(bmp, subBmp, dx,dy, cx, cy, degrees_to_fixed(rot));
2920 break;
2921
2922 case 4:
2923 //flip v
2924 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2925 draw_sprite_v_flip(bmp, subBmp, dx, dy);
2926 break;
2927
2928 case 5:
2929 //trans + v flip
2930 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2931 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
2932 break;
2933
2934 case 6:
2935 //pivot + v flip
2936 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2937 pivot_sprite_v_flip(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
2938 break;
2939
2940 case 8:
2941 //vlip h
2942 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2943 draw_sprite_h_flip(bmp, subBmp, dx, dy);
2944 break;
2945
2946 case 9:
2947 //trans + h flip
2948 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2949 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
2950 break;
2951
2952 case 10:
2953 //flip H and pivot
2954 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
2955 //return error cannot pivot and h flip
2956 break;
2957
2958 case 12:
2959 //vh flip
2960 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2961 draw_sprite_vh_flip(bmp, subBmp, dx, dy);
2962 break;
2963
2964 case 13:
2965 //trans + vh flip
2966 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2967 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
2968 break;
2969
2970 case 14:
2971 //pivot and vh flip
2972 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
2973 //return error cannot both pivot and vh flip
2974 break;
2975
2976 case 16:
2977 //lit
2978 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2979 draw_lit_sprite(bmp, subBmp, dx, dy, litcolour);
2980 break;
2981
2982 case 18:
2983 //pivot, lit
2984 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2985 pivot_sprite_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
2986 break;
2987
2988 case 20:
2989 //lit + v flip
2990 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2991 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
2992 break;
2993
2994 case 22:
2995 //Pivot, vflip, lit
2996 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2997 pivot_sprite_v_flip_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
2998 break;
2999
3000 case 24:
3001 //lit + h flip
3002 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3003 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
3004 break;
3005
3006 case 26:
3007 //pivot + lit + hflip
3008 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
3009 //return error cannot pivot, lit, and flip
3010 break;
3011
3012 case 28:
3013 //lit + vh flip
3014 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3015 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
3016 break;
3017
3018 case 32: //gouraud
3019 //Probably not wort supporting.
3020 //stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3021 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
3022 break;
3023
3024 case 0:
3025 //no effect
3026 stretch_blit(sourceBitmap, bmp, sx, sy, sw, sh, dx, dy, dw, dh);
3027 break;
3028
3029
3030 default:
3031 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
3032
3033
3034 }
3035 } //end if not rotated
3036
3037 if ( rot != 0 ) //if rotated
3038 {
3039 switch(mode)
3040 {
3041 case 1:
3042 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
3043 rotate_sprite_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3044
3045 break;
3046
3047 case 2:
3048 //pivot?
3049 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3050 //return an error, cannot both rotate and pivot
3051 break;
3052
3053 case 3:
3054 //pivot + trans
3055 //return an error, cannot both rotate and pivot
3056 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3057 break;
3058
3059 case 4:
3060 //flip v
3061 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3062 rotate_sprite_v_flip(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3063 break;
3064
3065 case 5:
3066 //trans + v flip
3067 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3068 rotate_sprite_v_flip_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3069 break;
3070
3071 case 6:
3072 //pivot + v flip
3073 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3074 //return an error, cannot both rotate and pivot
3075 break;
3076
3077 case 8:
3078 //flip h
3079 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
3080 //return an error, cannot both rotate and flip H
3081 break;
3082
3083 case 9:
3084 //trans + h flip
3085 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
3086 //return an error, cannot rotate and flip a trans sprite
3087 break;
3088
3089 case 10:
3090 //flip H and pivot
3091 //return error cannot pivot and h flip
3092 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
3093 break;
3094
3095 case 12:
3096 //vh flip
3097 //return an error, cannot rotate and VH flip a trans sprite
3098 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
3099 break;
3100
3101 case 13:
3102 //trans + vh flip
3103 //return an error, cannot rotate and VH flip a trans sprite
3104 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
3105 break;
3106
3107 case 14:
3108 //pivot and vh flip
3109 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3110 //return error cannot both pivot and vh flip
3111 break;
3112
3113 case 16:
3114 //lit
3115 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
3116 rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
3117 break;
3118
3119 case 18:
3120 //pivot, lit
3121 //return an error, cannot both rotate and pivot
3122 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3123 break;
3124
3125 case 20:
3126 //lit + vflip
3127 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
3128 rotate_sprite_v_flip_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
3129 break;
3130
3131 case 22:
3132 //Pivot, vflip, lit
3133 //return an error, cannot both rotate and pivot
3134 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3135 break;
3136
3137 case 24:
3138 //lit + h flip
3139 //return an error, cannot both rotate and H flip
3140 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
3141 break;
3142
3143 case 26:
3144 //pivot + lit + hflip
3145 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
3146 //return error cannot pivot, lit, and flip
3147 break;
3148
3149 case 28:
3150 //lit + vh flip
3151 //return an error, cannot both rotate and VH flip
3152 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
3153 break;
3154
3155 case 32: //gouraud
3156 //Probably not wort supporting.
3157 //stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3158 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
3159 break;
3160
3161 case 0:
3162 //no effect.
3163 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3164 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3165 break;
3166
3167 default:
3168 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
3169
3170 }
3171 }
3172
3173 } //end if stretched, but not masked
3174 }
3175 else //not stretched
3176 {
3177
3178 if(masked) //if masked, but not stretched
3179 {
3180
3181 if ( rot == 0 ) //if not rotated
3182 {
3183 switch(mode)
3184 {
3185 case 1:
3186 //transparent
3187 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3188 draw_trans_sprite(bmp, subBmp, dx, dy);
3189 break;
3190
3191
3192 case 2:
3193 //pivot?
3194 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3195 pivot_sprite(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3196 //Pivoting requires two more args
3197 break;
3198
3199 case 3:
3200 //pivot + trans
3201 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3202 pivot_sprite_trans(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3203 break;
3204
3205 case 4:
3206 //flip v
3207 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3208 draw_sprite_v_flip(bmp, subBmp, dx, dy);
3209 break;
3210
3211 case 5:
3212 //trans + v flip
3213 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3214 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
3215 break;
3216
3217 case 6:
3218 //pivot + v flip
3219 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3220 pivot_sprite_v_flip(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3221 break;
3222
3223 case 8:
3224 //vlip h
3225 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3226 draw_sprite_h_flip(bmp, subBmp, dx, dy);
3227 break;
3228
3229 case 9:
3230 //trans + h flip
3231 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3232 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
3233 break;
3234
3235 case 10:
3236 //flip H and pivot
3237 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
3238 //return error cannot pivot and h flip
3239 break;
3240
3241 case 12:
3242 //vh flip
3243 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3244 draw_sprite_vh_flip(bmp, subBmp, dx, dy);
3245 break;
3246
3247 case 13:
3248 //trans + vh flip
3249 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3250 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
3251 break;
3252
3253 case 14:
3254 //pivot and vh flip
3255 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
3256 //return error cannot both pivot and vh flip
3257 break;
3258
3259 case 16:
3260 //lit
3261 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3262 draw_lit_sprite(bmp, subBmp, dx, dy, litcolour);
3263 break;
3264
3265 case 18:
3266 //pivot, lit
3267 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3268 pivot_sprite_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
3269 break;
3270
3271 case 20:
3272 //lit + v flip
3273 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3274 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
3275 break;
3276
3277 case 22:
3278 //Pivot, vflip, lit
3279 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3280 pivot_sprite_v_flip_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
3281 break;
3282
3283 case 24:
3284 //lit + h flip
3285 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3286 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
3287 break;
3288
3289 case 26:
3290 //pivot + lit + hflip
3291 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
3292 //return error cannot pivot, lit, and flip
3293 break;
3294
3295 case 28:
3296 //lit + vh flip
3297 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3298 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
3299 break;
3300
3301 case 32: //gouraud
3302 //Probably not wort supporting.
3303 //stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3304 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
3305 break;
3306
3307 case 0:
3308 //no effect
3309 masked_blit(sourceBitmap, bmp, sx, sy, dx, dy, dw, dh);
3310 break;
3311
3312
3313 default:
3314 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
3315
3316
3317 }
3318 } //end if not rotated
3319
3320 if ( rot != 0 ) //if rotated
3321 {
3322 switch(mode)
3323 {
3324 case 1:
3325 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh); //transparent
3326 rotate_sprite_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3327
3328 break;
3329
3330 case 2:
3331 //pivot?
3332 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3333 //return an error, cannot both rotate and pivot
3334 break;
3335
3336 case 3:
3337 //pivot + trans
3338 //return an error, cannot both rotate and pivot
3339 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3340 break;
3341
3342 case 4:
3343 //flip v
3344 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3345 rotate_sprite_v_flip(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3346 break;
3347
3348 case 5:
3349 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh); //trans + v flip
3350 rotate_sprite_v_flip_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3351 break;
3352
3353 case 6:
3354 //pivot + v flip
3355 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3356 //return an error, cannot both rotate and pivot
3357 break;
3358
3359 case 8:
3360 //flip h
3361 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
3362 //return an error, cannot both rotate and flip H
3363 break;
3364
3365 case 9:
3366 //trans + h flip
3367 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
3368 //return an error, cannot rotate and flip a trans sprite
3369 break;
3370
3371 case 10:
3372 //flip H and pivot
3373 //return error cannot pivot and h flip
3374 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
3375 break;
3376
3377 case 12:
3378 //vh flip
3379 //return an error, cannot rotate and VH flip a trans sprite
3380 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
3381 break;
3382
3383 case 13:
3384 //trans + vh flip
3385 //return an error, cannot rotate and VH flip a trans sprite
3386 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
3387 break;
3388
3389 case 14:
3390 //pivot and vh flip
3391 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3392 //return error cannot both pivot and vh flip
3393 break;
3394
3395 case 16:
3396 //lit
3397 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3398 rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
3399 break;
3400
3401 case 18:
3402 //pivot, lit
3403 //return an error, cannot both rotate and pivot
3404 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3405 break;
3406
3407 case 20:
3408 //lit + vflip
3409 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3410 rotate_sprite_v_flip_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
3411 break;
3412
3413 case 22:
3414 //Pivot, vflip, lit
3415 //return an error, cannot both rotate and pivot
3416 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3417 break;
3418
3419 case 24:
3420 //lit + h flip
3421 //return an error, cannot both rotate and H flip
3422 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
3423 break;
3424
3425 case 26:
3426 //pivot + lit + hflip
3427 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
3428 //return error cannot pivot, lit, and flip
3429 break;
3430
3431 case 28:
3432 //lit + vh flip
3433 //return an error, cannot both rotate and VH flip
3434 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
3435 break;
3436
3437 case 32: //gouraud
3438 //Probably not wort supporting.
3439 //stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3440 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
3441 break;
3442
3443 case 0:
3444 //no effect.
3445 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3446 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3447 break;
3448
3449 default:
3450 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
3451
3452 }
3453 } //end rtated, masked
3454 } //end if masked
3455
3456 else //not masked, and not stretched; just blit
3457 {
3458
3459 if ( rot == 0 ) //if not rotated
3460 {
3461 switch(mode)
3462 {
3463 case 1:
3464 //transparent
3465 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3466 draw_trans_sprite(bmp, subBmp, dx, dy);
3467 break;
3468
3469
3470 case 2:
3471 //pivot?
3472 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3473 pivot_sprite(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3474 //Pivoting requires two more args
3475 break;
3476
3477 case 3:
3478 //pivot + trans
3479 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3480 pivot_sprite_trans(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3481 break;
3482
3483 case 4:
3484 //flip v
3485 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3486 draw_sprite_v_flip(bmp, subBmp, dx, dy);
3487 break;
3488
3489 case 5:
3490 //trans + v flip
3491 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3492 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
3493 break;
3494
3495 case 6:
3496 //pivot + v flip
3497 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3498 pivot_sprite_v_flip(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3499 break;
3500
3501 case 8:
3502 //vlip h
3503 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3504 draw_sprite_h_flip(bmp, subBmp, dx, dy);
3505 break;
3506
3507 case 9:
3508 //trans + h flip
3509 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3510 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
3511 break;
3512
3513 case 10:
3514 //flip H and pivot
3515 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
3516 //return error cannot pivot and h flip
3517 break;
3518
3519 case 12:
3520 //vh flip
3521 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3522 draw_sprite_vh_flip(bmp, subBmp, dx, dy);
3523 break;
3524
3525 case 13:
3526 //trans + vh flip
3527 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3528 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
3529 break;
3530
3531 case 14:
3532 //pivot and vh flip
3533 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
3534 //return error cannot both pivot and vh flip
3535 break;
3536
3537 case 16:
3538 //lit
3539 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3540 draw_lit_sprite(bmp, subBmp, dx, dy, litcolour);
3541 break;
3542
3543 case 18:
3544 //pivot, lit
3545 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3546 pivot_sprite_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
3547 break;
3548
3549 case 20:
3550 //lit + v flip
3551 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3552 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
3553 break;
3554
3555 case 22:
3556 //Pivot, vflip, lit
3557 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3558 pivot_sprite_v_flip_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
3559 break;
3560
3561 case 24:
3562 //lit + h flip
3563 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3564 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
3565 break;
3566
3567 case 26:
3568 //pivot + lit + hflip
3569 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
3570 //return error cannot pivot, lit, and flip
3571 break;
3572
3573 case 28:
3574 //lit + vh flip
3575 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3576 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
3577 break;
3578
3579 case 32: //gouraud
3580 //Probably not wort supporting.
3581 //blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3582 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
3583 break;
3584
3585 case 0:
3586 //no effect
3587 blit(sourceBitmap, bmp, sx, sy, dx, dy, dw, dh);
3588 break;
3589
3590
3591 default:
3592 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
3593
3594
3595 }
3596 } //end if not rotated
3597
3598 if ( rot != 0 ) //if rotated
3599 {
3600 switch(mode)
3601 {
3602 case 1:
3603 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);//transparent
3604 rotate_sprite_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3605
3606 break;
3607
3608 case 2:
3609 //pivot?
3610 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3611 //return an error, cannot both rotate and pivot
3612 break;
3613
3614 case 3:
3615 //pivot + trans
3616 //return an error, cannot both rotate and pivot
3617 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3618 break;
3619
3620 case 4:
3621 //flip v
3622 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3623 rotate_sprite_v_flip(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3624 break;
3625
3626 case 5:
3627 //trans + v flip
3628 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3629 rotate_sprite_v_flip_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3630 break;
3631
3632 case 6:
3633 //pivot + v flip
3634 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3635 //return an error, cannot both rotate and pivot
3636 break;
3637
3638 case 8:
3639 //flip h
3640 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
3641 //return an error, cannot both rotate and flip H
3642 break;
3643
3644 case 9:
3645 //trans + h flip
3646 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
3647 //return an error, cannot rotate and flip a trans sprite
3648 break;
3649
3650 case 10:
3651 //flip H and pivot
3652 //return error cannot pivot and h flip
3653 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
3654 break;
3655
3656 case 12:
3657 //vh flip
3658 //return an error, cannot rotate and VH flip a trans sprite
3659 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
3660 break;
3661
3662 case 13:
3663 //trans + vh flip
3664 //return an error, cannot rotate and VH flip a trans sprite
3665 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
3666 break;
3667
3668 case 14:
3669 //pivot and vh flip
3670 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3671 //return error cannot both pivot and vh flip
3672 break;
3673
3674 case 16:
3675 //lit
3676 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3677 rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
3678 break;
3679
3680 case 18:
3681 //pivot, lit
3682 //return an error, cannot both rotate and pivot
3683 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3684 break;
3685
3686 case 20:
3687 //lit + vflip
3688 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3689 rotate_sprite_v_flip_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
3690 break;
3691
3692 case 22:
3693 //Pivot, vflip, lit
3694 //return an error, cannot both rotate and pivot
3695 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3696 break;
3697
3698 case 24:
3699 //lit + h flip
3700 //return an error, cannot both rotate and H flip
3701 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
3702 break;
3703
3704 case 26:
3705 //pivot + lit + hflip
3706 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
3707 //return error cannot pivot, lit, and flip
3708 break;
3709
3710 case 28:
3711 //lit + vh flip
3712 //return an error, cannot both rotate and VH flip
3713 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
3714 break;
3715
3716 case 32: //gouraud
3717 //Probably not wort supporting.
3718 //blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3719 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
3720 break;
3721
3722 case 0:
3723 //no effect.
3724 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3725 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3726 break;
3727
3728 default:
3729 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
3730
3731 }
3732 } //end if rotated
3733 } //end if not masked
3734 } //end if not stretched
3735
3736 //cleanup
3737 if(subBmp)
3738 {
3739 script_drawing_commands.ReleaseSubBitmap(subBmp); //purge the temporary bitmap.
3740 }
3741 }
3742
3743
3744 void do_drawquad3dr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
3745 {
3746 //sdci[1]=layer
3747 //sdci[2]=pos[12]
3748 //sdci[3]=uv[8]
3749 //sdci[4]=color[4]
3750 //sdci[5]=size[2]
3751 //sdci[6]=flip
3752 //sdci[7]=tile/combo
3753 //sdci[8]=polytype
3754
3755 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
3756
3757 if(!v_ptr)
3758 {
3759 al_trace("Quad3d: Vector pointer is null! Internal error. \n");
3760 return;
3761 }
3762
3763 std::vector<int32_t> &v = *v_ptr;
3764
3765 if(v.empty())
3766 return;
3767
3768 int32_t* pos = &v[0];
3769 int32_t* uv = &v[12];
3770 int32_t* col = &v[20];
3771 int32_t* size = &v[24];
3772
3773 int32_t w = size[0]; //magic numerical constants... yuck.
3774 int32_t h = size[1];
3775 int32_t flip = (sdci[6]/10000)&3;
3776 int32_t tile = sdci[7]/10000;
3777 int32_t polytype = sdci[8]/10000;
3778
3779 polytype = vbound(polytype, 0, 14);
3780
3781 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
3782 {
3783 Z_message("Quad3d() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
3784 return; //non power of two error
3785 }
3786
3787 int32_t tex_width = w*16;
3788 int32_t tex_height = h*16;
3789
3790 bool mustDestroyBmp = false;
3791 BITMAP *tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
3792
3793 if(!tex)
3794 {
3795 mustDestroyBmp = true;
3796 tex = create_bitmap_ex(8, tex_width, tex_height);
3797 clear_bitmap(tex);
3798 }
3799
3800 if(tile > 0) // TILE
3801 {
3802 TileHelper::OverTile(tex, tile, 0, 0, w, h, col[0], flip);
3803 }
3804 else // COMBO
3805 {
3806 auto& c = GET_DRAWING_COMBO(vbound(abs(tile), 0, 0xffff));
3807 const int32_t tiletodraw = combo_tile(c, 0, 0);
3808 flip = flip ^ c.flip;
3809
3810 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, col[0], flip);
3811 }
3812
3813 V3D_f V1 = { static_cast<float>(pos[0]+xoffset), static_cast<float>(pos[1] +yoffset), static_cast<float>(pos[2]), static_cast<float>(uv[0]), static_cast<float>(uv[1]), col[0] };
3814 V3D_f V2 = { static_cast<float>(pos[3]+xoffset), static_cast<float>(pos[4] +yoffset), static_cast<float>(pos[5]), static_cast<float>(uv[2]), static_cast<float>(uv[3]), col[1] };
3815 V3D_f V3 = { static_cast<float>(pos[6]+xoffset), static_cast<float>(pos[7] +yoffset), static_cast<float>(pos[8]), static_cast<float>(uv[4]), static_cast<float>(uv[5]), col[2] };
3816 V3D_f V4 = { static_cast<float>(pos[9]+xoffset), static_cast<float>(pos[10]+yoffset), static_cast<float>(pos[11]), static_cast<float>(uv[6]), static_cast<float>(uv[7]), col[3] };
3817
3818 quad3d_f(bmp, polytype, tex, &V1, &V2, &V3, &V4);
3819
3820 if(mustDestroyBmp)
3821 destroy_bitmap(tex);
3822
3823 }
3824
3825
3826
3827 void do_drawtriangle3dr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
3828 {
3829 //sdci[1]=layer
3830 //sdci[2]=pos[9]
3831 //sdci[3]=uv[6]
3832 //sdci[4]=color[3]
3833 //sdci[5]=size[2]
3834 //sdci[6]=flip
3835 //sdci[7]=tile/combo
3836 //sdci[8]=polytype
3837
3838 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
3839
3840 if(!v_ptr)
3841 {
3842 al_trace("Triange3d: Vector pointer is null! Internal error. \n");
3843 return;
3844 }
3845
3846 std::vector<int32_t> &v = *v_ptr;
3847
3848 if(v.empty())
3849 return;
3850
3851 int32_t* pos = &v[0];
3852 int32_t* uv = &v[9];
3853 int32_t* col = &v[15];
3854 int32_t* size = &v[18];
3855
3856 int32_t w = size[0]; //magic numerical constants... yuck.
3857 int32_t h = size[1];
3858 int32_t flip = (sdci[6]/10000)&3;
3859 int32_t tile = sdci[7]/10000;
3860 int32_t polytype = sdci[8]/10000;
3861
3862 polytype = vbound(polytype, 0, 14);
3863
3864 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
3865 {
3866 Z_message("Triangle3d() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
3867 return; //non power of two error
3868 }
3869
3870 int32_t tex_width = w*16;
3871 int32_t tex_height = h*16;
3872
3873 bool mustDestroyBmp = false;
3874 BITMAP *tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
3875
3876 if(!tex)
3877 {
3878 mustDestroyBmp = true;
3879 tex = create_bitmap_ex(8, tex_width, tex_height);
3880 clear_bitmap(tex);
3881 }
3882
3883 if(tile > 0) // TILE
3884 {
3885 TileHelper::OverTile(tex, tile, 0, 0, w, h, col[0], flip);
3886 }
3887 else // COMBO
3888 {
3889 auto& c = GET_DRAWING_COMBO(vbound(abs(tile), 0, 0xffff));
3890 const int32_t tiletodraw = combo_tile(c, 0, 0);
3891 flip = flip ^ c.flip;
3892
3893 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, col[0], flip);
3894 }
3895
3896 V3D_f V1 = { static_cast<float>(pos[0]+xoffset), static_cast<float>(pos[1] +yoffset), static_cast<float>(pos[2]), static_cast<float>(uv[0]), static_cast<float>(uv[1]), col[0] };
3897 V3D_f V2 = { static_cast<float>(pos[3]+xoffset), static_cast<float>(pos[4] +yoffset), static_cast<float>(pos[5]), static_cast<float>(uv[2]), static_cast<float>(uv[3]), col[1] };
3898 V3D_f V3 = { static_cast<float>(pos[6]+xoffset), static_cast<float>(pos[7] +yoffset), static_cast<float>(pos[8]), static_cast<float>(uv[4]), static_cast<float>(uv[5]), col[2] };
3899
3900 triangle3d_f(bmp, polytype, tex, &V1, &V2, &V3);
3901
3902 if(mustDestroyBmp)
3903 destroy_bitmap(tex);
3904
3905 }
3906
3907 7971 void bmp_do_rectr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
3908 {
3909 //Z_scripterrlog("rect sdci[13] is: %d\n", sdci[13]);
3910 //sdci[1]=layer
3911 //sdci[2]=x
3912 //sdci[3]=y
3913 //sdci[4]=x2
3914 //sdci[5]=y2
3915 //sdci[6]=color
3916 //sdci[7]=scale factor
3917 //sdci[8]=rotation anchor x
3918 //sdci[9]=rotation anchor y
3919 //sdci[10]=rotation angle
3920 //sdci[11]=fill
3921 //sdci[12]=opacity
3922 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
3923
1/2
✓ Branch 0 taken 7971 times.
✗ Branch 1 not taken.
7971 if(sdci[7]==0) //scale
3924 {
3925 return;
3926 }
3927
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7971 times.
7971 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
3928 {
3929 Z_scripterrlog("bitmap->Rectangle() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
3930 return;
3931 }
3932 7971 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
3933
1/2
✓ Branch 0 taken 7971 times.
✗ Branch 1 not taken.
7971 if ( refbmp == NULL ) return;
3934
3935
2/4
✓ Branch 0 taken 7971 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 7971 times.
7971 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
3936
3937 7971 int32_t x1=sdci[2]/10000;
3938 7971 int32_t y1=sdci[3]/10000;
3939 7971 int32_t x2=sdci[4]/10000;
3940 7971 int32_t y2=sdci[5]/10000;
3941
3942
3943
2/2
✓ Branch 0 taken 7967 times.
✓ Branch 1 taken 4 times.
7971 if(x1>x2)
3944 {
3945 4 zc_swap(x1,x2);
3946 4 }
3947
3948
2/2
✓ Branch 0 taken 7967 times.
✓ Branch 1 taken 4 times.
7971 if(y1>y2)
3949 {
3950 4 zc_swap(y1,y2);
3951 4 }
3952
3953
1/2
✓ Branch 0 taken 7971 times.
✗ Branch 1 not taken.
7971 if(sdci[7] != 10000)
3954 {
3955 int32_t w=x2-x1+1;
3956 int32_t h=y2-y1+1;
3957 int32_t w2=(w*sdci[7])/10000;
3958 int32_t h2=(h*sdci[7])/10000;
3959 x1=x1-((w2-w)/2);
3960 x2=x2+((w2-w)/2);
3961 y1=y1-((h2-h)/2);
3962 y2=y2+((h2-h)/2);
3963 }
3964
3965 7971 int32_t color=sdci[6]/10000;
3966
3967
2/2
✓ Branch 0 taken 7843 times.
✓ Branch 1 taken 128 times.
7971 if(sdci[12]/10000<=127) //translucent
3968 {
3969 128 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
3970 128 }
3971
3972
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 7875 times.
7971 if(sdci[10]==0) //no rotation
3973 {
3974
2/2
✓ Branch 0 taken 7863 times.
✓ Branch 1 taken 12 times.
7875 if(sdci[11]) //filled
3975 {
3976 7863 rectfill(refbmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
3977 7863 }
3978 else //outline
3979 {
3980 12 rect(refbmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
3981 }
3982 7875 }
3983 else //rotate
3984 {
3985 int32_t xy[16];
3986 96 int32_t rx=sdci[8]/10000;
3987 96 int32_t ry=sdci[9]/10000;
3988 96 fixed ra1=itofix(sdci[10]%10000)/10000;
3989 96 fixed ra2=itofix(sdci[10]/10000);
3990 96 fixed ra=ra1+ra2;
3991 96 ra = (ra/360)*256;
3992
3993 96 fixed fcosa = fixcos(ra);
3994 96 fixed fsina = fixsin(ra);
3995
3996 96 xy[ 0]=xoffset+rx + fixtoi((fcosa * (x1 - rx) - fsina * (y1 - ry))); //x1
3997 96 xy[ 1]=yoffset+ry + fixtoi((fsina * (x1 - rx) + fcosa * (y1 - ry))); //y1
3998 96 xy[ 2]=xoffset+rx + fixtoi((fcosa * (x2 - rx) - fsina * (y1 - ry))); //x2
3999 96 xy[ 3]=yoffset+ry + fixtoi((fsina * (x2 - rx) + fcosa * (y1 - ry))); //y1
4000 96 xy[ 4]=xoffset+rx + fixtoi((fcosa * (x2 - rx) - fsina * (y2 - ry))); //x2
4001 96 xy[ 5]=yoffset+ry + fixtoi((fsina * (x2 - rx) + fcosa * (y2 - ry))); //y2
4002 96 xy[ 6]=xoffset+rx + fixtoi((fcosa * (x1 - rx) - fsina * (y2 - ry))); //x1
4003 96 xy[ 7]=yoffset+ry + fixtoi((fsina * (x1 - rx) + fcosa * (y2 - ry))); //y2
4004 96 xy[ 8]=xoffset+rx + fixtoi((fcosa * (x1 - rx) - fsina * (y1 - ry + 1))); //x1
4005 96 xy[ 9]=yoffset+ry + fixtoi((fsina * (x1 - rx) + fcosa * (y1 - ry + 1))); //y1
4006 96 xy[10]=xoffset+rx + fixtoi((fcosa * (x2 - rx - 1) - fsina * (y1 - ry))); //x2
4007 96 xy[11]=yoffset+ry + fixtoi((fsina * (x2 - rx - 1) + fcosa * (y1 - ry))); //y1
4008 96 xy[12]=xoffset+rx + fixtoi((fcosa * (x2 - rx) - fsina * (y2 - ry - 1))); //x2
4009 96 xy[13]=yoffset+ry + fixtoi((fsina * (x2 - rx) + fcosa * (y2 - ry - 1))); //y2
4010 96 xy[14]=xoffset+rx + fixtoi((fcosa * (x1 - rx + 1) - fsina * (y2 - ry))); //x1
4011 96 xy[15]=yoffset+ry + fixtoi((fsina * (x1 - rx + 1) + fcosa * (y2 - ry))); //y2
4012
4013
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 if(sdci[11]) //filled
4014 {
4015 96 polygon(refbmp, 4, xy, color);
4016 96 }
4017 else //outline
4018 {
4019 line(refbmp, xy[0], xy[1], xy[10], xy[11], color);
4020 line(refbmp, xy[2], xy[3], xy[12], xy[13], color);
4021 line(refbmp, xy[4], xy[5], xy[14], xy[15], color);
4022 line(refbmp, xy[6], xy[7], xy[ 8], xy[ 9], color);
4023 }
4024 }
4025
4026 7971 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
4027 7971 }
4028
4029 void bmp_do_framer(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4030 {
4031 //sdci[1]=layer
4032 //sdci[2]=x
4033 //sdci[3]=y
4034 //sdci[4]=tile
4035 //sdci[5]=cset
4036 //sdci[6]=width
4037 //sdci[7]=height
4038 //sdci[8]=overlay
4039 //sdci[9]=opacity
4040
4041 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4042 {
4043 Z_scripterrlog("bitmap->DrawFrame() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4044 return;
4045 }
4046 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
4047 if ( refbmp == NULL ) return;
4048
4049 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4050
4051 int32_t x=sdci[2]/10000;
4052 int32_t y=sdci[3]/10000;
4053
4054 int32_t tile=sdci[4]/10000;
4055 int32_t cs=sdci[5]/10000;
4056 int32_t w=sdci[6]/10000;
4057 int32_t h=sdci[7]/10000;
4058 bool overlay=sdci[8];
4059 bool trans=(sdci[9]/10000<=127);
4060
4061 frame2x2(refbmp, x + xoffset, y + yoffset, tile, cs, w, h, 0, overlay, trans);
4062 }
4063
4064
4065 148823 void bmp_do_circler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4066 {
4067 //sdci[1]=layer
4068 //sdci[2]=x
4069 //sdci[3]=y
4070 //sdci[4]=radius
4071 //sdci[5]=color
4072 //sdci[6]=scale factor
4073 //sdci[7]=rotation anchor x
4074 //sdci[8]=rotation anchor y
4075 //sdci[9]=rotation angle
4076 //sdci[10]=fill
4077 //sdci[11]=opacity
4078 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4079
1/2
✓ Branch 0 taken 148823 times.
✗ Branch 1 not taken.
148823 if(sdci[6]==0) //scale
4080 {
4081 return;
4082 }
4083
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 148823 times.
148823 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4084 {
4085 Z_scripterrlog("bitmap->Circle() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4086 return;
4087 }
4088 148823 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
4089
1/2
✓ Branch 0 taken 148823 times.
✗ Branch 1 not taken.
148823 if ( refbmp == NULL ) return;
4090
4091
2/4
✓ Branch 0 taken 148823 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 148823 times.
148823 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4092
4093 148823 int32_t x1=sdci[2]/10000;
4094 148823 int32_t y1=sdci[3]/10000;
4095 148823 qword r=sdci[4];
4096
4097
1/2
✓ Branch 0 taken 148823 times.
✗ Branch 1 not taken.
148823 if(sdci[6] != 10000)
4098 {
4099 r*=sdci[6];
4100 r/=10000;
4101 }
4102
4103 148823 r/=10000;
4104 148823 int32_t color=sdci[5]/10000;
4105
4106
1/2
✓ Branch 0 taken 148823 times.
✗ Branch 1 not taken.
148823 if(sdci[11]/10000<=127) //translucent
4107 {
4108 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
4109 }
4110
4111
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 148823 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
148823 if(sdci[9]!=0&&(sdci[2]!=sdci[7]||sdci[3]!=sdci[8])) //rotation
4112 {
4113 int32_t xy[2];
4114 int32_t rx=sdci[7]/10000;
4115 int32_t ry=sdci[8]/10000;
4116 fixed ra1=itofix(sdci[9]%10000)/10000;
4117 fixed ra2=itofix(sdci[9]/10000);
4118 fixed ra=ra1+ra2;
4119 ra = (ra/360)*256;
4120
4121 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
4122 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
4123 x1=xy[0];
4124 y1=xy[1];
4125 }
4126
4127
1/2
✓ Branch 0 taken 148823 times.
✗ Branch 1 not taken.
148823 if(sdci[10]) //filled
4128 {
4129 148823 circlefill(refbmp, x1+xoffset, y1+yoffset, r, color);
4130 148823 }
4131 else //outline
4132 {
4133 circle(refbmp, x1+xoffset, y1+yoffset, r, color);
4134 }
4135
4136 148823 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
4137 148823 }
4138
4139
4140 void bmp_do_arcr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4141 {
4142 //sdci[1]=layer
4143 //sdci[2]=x
4144 //sdci[3]=y
4145 //sdci[4]=radius
4146 //sdci[5]=start angle
4147 //sdci[6]=end angle
4148 //sdci[7]=color
4149 //sdci[8]=scale factor
4150 //sdci[9]=rotation anchor x
4151 //sdci[10]=rotation anchor y
4152 //sdci[11]=rotation angle
4153 //sdci[12]=closed
4154 //sdci[13]=fill
4155 //sdci[14]=opacity
4156 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4157
4158 if(sdci[8]==0) //scale
4159 {
4160 return;
4161 }
4162 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4163 {
4164 Z_scripterrlog("bitmap->Arc() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4165 return;
4166 }
4167 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
4168 if ( refbmp == NULL ) return;
4169
4170 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4171
4172 int32_t cx=sdci[2]/10000;
4173 int32_t cy=sdci[3]/10000;
4174 qword r=sdci[4];
4175
4176 if(sdci[8] != 10000)
4177 {
4178 r*=sdci[8];
4179 r/=10000;
4180 }
4181
4182 r/=10000;
4183
4184 int32_t color=sdci[7]/10000;
4185
4186 fixed ra1=itofix(sdci[11]%10000)/10000;
4187 fixed ra2=itofix(sdci[11]/10000);
4188 fixed ra=ra1+ra2;
4189 ra = (ra/360)*256;
4190
4191
4192 fixed a1=itofix(sdci[5]%10000)/10000;
4193 fixed a2=itofix(sdci[5]/10000);
4194 fixed sa=a1+a2;
4195 sa = (sa/360)*256;
4196
4197 a1=itofix(sdci[6]%10000)/10000;
4198 a2=itofix(sdci[6]/10000);
4199 fixed ea=a1+a2;
4200 ea = (ea/360)*256;
4201
4202 if(sdci[11]!=0) //rotation
4203 {
4204 int32_t rx=sdci[9]/10000;
4205 int32_t ry=sdci[10]/10000;
4206
4207 cx=rx + fixtoi((fixcos(ra) * (cx - rx) - fixsin(ra) * (cy - ry))); //x1
4208 cy=ry + fixtoi((fixsin(ra) * (cx - rx) + fixcos(ra) * (cy - ry))); //y1
4209 ea-=ra;
4210 sa-=ra;
4211 }
4212
4213 int32_t fx=cx+fixtoi(fixcos(-(ea+sa)/2)*r/2);
4214 int32_t fy=cy+fixtoi(fixsin(-(ea+sa)/2)*r/2);
4215
4216 if(sdci[12]) //closed
4217 {
4218 if(sdci[13]) //filled
4219 {
4220 clear_bitmap(prim_bmp);
4221 arc(prim_bmp, cx+xoffset, cy+yoffset, sa, ea, int32_t(r), color);
4222 line(prim_bmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-sa)*r), cy+yoffset+fixtoi(fixsin(-sa)*r), color);
4223 line(prim_bmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-ea)*r), cy+yoffset+fixtoi(fixsin(-ea)*r), color);
4224 int fillx = zc_max(0,fx)+xoffset;
4225 int filly = zc_max(0,fy)+yoffset;
4226 zprint2("bitmap->Arc fill at prim_bmp (%d,%d) - 512x512\n", fillx, filly);
4227 floodfill(prim_bmp, fillx, filly, color);
4228
4229 if(sdci[14]/10000<=127) //translucent
4230 {
4231 draw_trans_sprite(refbmp, prim_bmp, 0,0);
4232 }
4233 else
4234 {
4235 draw_sprite(refbmp, prim_bmp, 0,0);
4236 }
4237 }
4238 else
4239 {
4240 arc(refbmp, cx+xoffset, cy+yoffset, sa, ea, int32_t(r), color);
4241 line(refbmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-sa)*r), cy+yoffset+fixtoi(fixsin(-sa)*r), color);
4242 line(refbmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-ea)*r), cy+yoffset+fixtoi(fixsin(-ea)*r), color);
4243 }
4244 }
4245 else
4246 {
4247 if(sdci[14]/10000<=127) //translucent
4248 {
4249 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
4250 }
4251
4252 arc(refbmp, cx+xoffset, cy+yoffset, sa, ea, int32_t(r), color);
4253 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
4254 }
4255 }
4256
4257
4258 502 void bmp_do_ellipser(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4259 {
4260 //sdci[1]=layer
4261 //sdci[2]=x
4262 //sdci[3]=y
4263 //sdci[4]=radiusx
4264 //sdci[5]=radiusy
4265 //sdci[6]=color
4266 //sdci[7]=scale factor
4267 //sdci[8]=rotation anchor x
4268 //sdci[9]=rotation anchor y
4269 //sdci[10]=rotation angle
4270 //sdci[11]=fill
4271 //sdci[12]=opacity
4272 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4273
4274
1/2
✓ Branch 0 taken 502 times.
✗ Branch 1 not taken.
502 if(sdci[7]==0) //scale
4275 {
4276 return;
4277 }
4278
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 502 times.
502 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4279 {
4280 Z_scripterrlog("bitmap->Ellipse() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4281 return;
4282 }
4283 502 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
4284
1/2
✓ Branch 0 taken 502 times.
✗ Branch 1 not taken.
502 if ( refbmp == NULL ) return;
4285
4286 502 int32_t x1=sdci[2]/10000;
4287 502 int32_t y1=sdci[3]/10000;
4288 502 int32_t radx=sdci[4]/10000;
4289 502 radx*=sdci[7]/10000;
4290 502 int32_t rady=sdci[5]/10000;
4291 502 rady*=sdci[7]/10000;
4292 502 int32_t color=sdci[6]/10000;
4293 502 float rotation = sdci[10]/10000;
4294
4295 502 int32_t rx=sdci[8]/10000;
4296 502 int32_t ry=sdci[9]/10000;
4297 502 fixed ra1=itofix(sdci[10]%10000)/10000;
4298 502 fixed ra2=itofix(sdci[10]/10000);
4299 502 fixed ra=ra1+ra2;
4300 502 ra = (ra/360)*256;
4301
4302
2/4
✓ Branch 0 taken 502 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 502 times.
✗ Branch 3 not taken.
502 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4303
4304 int32_t xy[2];
4305 502 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
4306 502 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
4307 502 x1=xy[0];
4308 502 y1=xy[1];
4309
4310
6/8
✓ Branch 0 taken 498 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 494 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 494 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 494 times.
502 if(radx<1||rady<1||radx>255||rady>255) return;
4311
4312 494 BITMAP* bitty = script_drawing_commands.AquireSubBitmap(radx*2+1, rady*2+1);
4313
4314
2/4
✓ Branch 0 taken 494 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 494 times.
494 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4315
4316
1/2
✓ Branch 0 taken 494 times.
✗ Branch 1 not taken.
494 if(sdci[11]) //filled
4317 {
4318
4319
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 494 times.
494 if(sdci[12]/10000<128) //translucent
4320 {
4321 clear_bitmap(prim_bmp);
4322 ellipsefill(bitty, radx, rady, radx, rady, color==0?255:color);
4323 rotate_sprite(prim_bmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
4324 draw_trans_sprite(refbmp, prim_bmp, 0, 0);
4325 }
4326 else // no opacity
4327 {
4328
2/2
✓ Branch 0 taken 432 times.
✓ Branch 1 taken 62 times.
494 ellipsefill(bitty, radx, rady, radx, rady, color==0?255:color);
4329 494 rotate_sprite(refbmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
4330 }
4331 494 }
4332 else //not filled
4333 {
4334 if(sdci[12]/10000<128) //translucent
4335 {
4336 clear_bitmap(prim_bmp);
4337 ellipse(bitty, radx, rady, radx, rady, color==0?255:color);
4338 rotate_sprite(prim_bmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
4339 draw_trans_sprite(refbmp, prim_bmp, 0, 0);
4340 }
4341 else // no opacity
4342 {
4343 ellipse(bitty, radx, rady, radx, rady, color==0?255:color);
4344 rotate_sprite(refbmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
4345 }
4346 }
4347
4348 // Since 0 is the transparent color, the stuff above will fail if the ellipse color is also 0.
4349 // Instead, it uses color 255 and replaces it afterward. That'll also screw up color 255 around
4350 // the ellipse, but it shouldn't be used anyway.
4351
2/2
✓ Branch 0 taken 432 times.
✓ Branch 1 taken 62 times.
494 if(color==0)
4352 {
4353 // This is very slow, so check the smallest possible square
4354
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 62 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 62 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 62 times.
62 int32_t endx=zc_min(bmp->w-1, x1+zc_max(radx, rady));
4355
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 62 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 62 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 62 times.
62 int32_t endy=zc_min(bmp->h-1, y1+zc_max(radx, rady));
4356
4357
6/8
✗ Branch 0 not taken.
✓ Branch 1 taken 62 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 60 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 4430 times.
✓ Branch 7 taken 62 times.
4492 for(int32_t y=zc_max(0, y1-zc_max(radx, rady)); y<=endy; y++)
4358
6/8
✗ Branch 0 not taken.
✓ Branch 1 taken 4430 times.
✓ Branch 2 taken 1086 times.
✓ Branch 3 taken 3344 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1086 times.
✓ Branch 6 taken 467774 times.
✓ Branch 7 taken 4430 times.
472204 for(int32_t x=zc_max(0, x1-zc_max(radx, rady)); x<=endx; x++)
4359
2/2
✓ Branch 0 taken 238992 times.
✓ Branch 1 taken 228782 times.
696556 if(getpixel(refbmp, x, y)==255)
4360 233212 putpixel(refbmp, x, y, 0);
4361 62 }
4362
4363 494 script_drawing_commands.ReleaseSubBitmap(bitty);
4364 502 }
4365
4366
4367 144 void bmp_do_liner(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4368 {
4369 //sdci[1]=layer
4370 //sdci[2]=x
4371 //sdci[3]=y
4372 //sdci[4]=x2
4373 //sdci[5]=y2
4374 //sdci[6]=color
4375 //sdci[7]=scale factor
4376 //sdci[8]=rotation anchor x
4377 //sdci[9]=rotation anchor y
4378 //sdci[10]=rotation angle
4379 //sdci[11]=opacity
4380 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4381
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(sdci[7]==0) //scale
4382 {
4383 return;
4384 }
4385
4386
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 144 times.
144 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4387 {
4388 Z_scripterrlog("bitmap->Line() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4389 return;
4390 }
4391
4392 144 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
4393
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if ( refbmp == NULL ) return;
4394
4395 144 int32_t x1=sdci[2]/10000;
4396 144 int32_t y1=sdci[3]/10000;
4397 144 int32_t x2=sdci[4]/10000;
4398 144 int32_t y2=sdci[5]/10000;
4399
4400
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(sdci[7] != 10000)
4401 {
4402 int32_t w=x2-x1+1;
4403 int32_t h=y2-y1+1;
4404 int32_t w2=int32_t(w*((double)sdci[7]/10000.0));
4405 int32_t h2=int32_t(h*((double)sdci[7]/10000.0));
4406 x1=x1-((w2-w)/2);
4407 x2=x2+((w2-w)/2);
4408 y1=y1-((h2-h)/2);
4409 y2=y2+((h2-h)/2);
4410 }
4411
4412 144 int32_t color=sdci[6]/10000;
4413
4414
2/4
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 144 times.
144 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4415
4416
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(sdci[11]/10000<=127) //translucent
4417 {
4418 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
4419 }
4420
4421
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(sdci[10]!=0) //rotation
4422 {
4423 int32_t xy[4];
4424 int32_t rx=sdci[8]/10000;
4425 int32_t ry=sdci[9]/10000;
4426 fixed ra1=itofix(sdci[10]%10000)/10000;
4427 fixed ra2=itofix(sdci[10]/10000);
4428 fixed ra=ra1+ra2;
4429
4430 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
4431 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
4432 xy[ 2]=rx + fixtoi((fixcos(ra) * (x2 - rx) - fixsin(ra) * (y2 - ry))); //x2
4433 xy[ 3]=ry + fixtoi((fixsin(ra) * (x2 - rx) + fixcos(ra) * (y2 - ry))); //y2
4434 x1=xy[0];
4435 y1=xy[1];
4436 x2=xy[2];
4437 y2=xy[3];
4438 }
4439
4440 144 line(refbmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
4441 144 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
4442 144 }
4443
4444
4445 void bmp_do_spliner(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4446 {
4447 /* layer, x1, y1, x2, y2, x3, y3, x4, y4, color, opacity */
4448 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4449
4450 int32_t points[8] = { xoffset + (sdci[2]/10000), yoffset + (sdci[3]/10000),
4451 xoffset + (sdci[4]/10000), yoffset + (sdci[5]/10000),
4452 xoffset + (sdci[6]/10000), yoffset + (sdci[7]/10000),
4453 xoffset + (sdci[8]/10000), yoffset + (sdci[9]/10000)
4454 };
4455
4456 if(sdci[11]/10000 < 128) //translucent
4457 {
4458 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
4459 }
4460
4461 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4462 {
4463 Z_scripterrlog("bitmap->Spline() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4464 return;
4465 }
4466
4467 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
4468 if ( refbmp == NULL ) return;
4469
4470 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4471
4472 spline(refbmp, points, sdci[10]/10000);
4473
4474 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
4475 }
4476
4477
4478 80910 void bmp_do_putpixelr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4479 {
4480 //sdci[1]=layer
4481 //sdci[2]=x
4482 //sdci[3]=y
4483 //sdci[4]=color
4484 //sdci[5]=rotation anchor x
4485 //sdci[6]=rotation anchor y
4486 //sdci[7]=rotation angle
4487 //sdci[8]=opacity
4488 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4489 80910 int32_t x1=sdci[2]/10000;
4490 80910 int32_t y1=sdci[3]/10000;
4491 80910 int32_t color=sdci[4]/10000;
4492
4493
1/2
✓ Branch 0 taken 80910 times.
✗ Branch 1 not taken.
80910 if(sdci[8]/10000<=127) //translucent
4494 {
4495 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
4496 }
4497
4498
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 80910 times.
80910 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4499 {
4500 Z_scripterrlog("bitmap->PutPixel() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4501 return;
4502 }
4503
4504 80910 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
4505
1/2
✓ Branch 0 taken 80910 times.
✗ Branch 1 not taken.
80910 if ( refbmp == NULL ) return;
4506
4507
2/4
✓ Branch 0 taken 80910 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 80910 times.
✗ Branch 3 not taken.
80910 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4508
4509
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 80910 times.
80910 if(sdci[7]!=0) //rotation
4510 {
4511 int32_t xy[2];
4512 int32_t rx=sdci[5]/10000;
4513 int32_t ry=sdci[6]/10000;
4514 fixed ra1=itofix(sdci[7]%10000)/10000;
4515 fixed ra2=itofix(sdci[7]/10000);
4516 fixed ra=ra1+ra2;
4517
4518 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
4519 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
4520 x1=xy[0];
4521 y1=xy[1];
4522 }
4523
4524 80910 putpixel(refbmp, x1+xoffset, y1+yoffset, color);
4525 80910 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
4526 80910 }
4527
4528
4529 59816 void bmp_do_drawtiler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4530 {
4531 //sdci[1]=layer
4532 //sdci[2]=x
4533 //sdci[3]=y
4534 //sdci[4]=tile
4535 //sdci[5]=tile width
4536 //sdci[6]=tile height
4537 //sdci[7]=color (cset)
4538 //sdci[8]=scale x
4539 //sdci[9]=scale y
4540 //sdci[10]=rotation anchor x
4541 //sdci[11]=rotation anchor y
4542 //sdci[12]=rotation angle
4543 //sdci[13]=flip
4544 //sdci[14]=transparency
4545 //sdci[15]=opacity
4546 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4547
4548 59816 int32_t w = sdci[5]/10000;
4549 59816 int32_t h = sdci[6]/10000;
4550
4551
4/8
✓ Branch 0 taken 59816 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 59816 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 59816 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 59816 times.
59816 if(w < 1 || h < 1 || h > 20 || w > 20)
4552 {
4553 return;
4554 }
4555
4556
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 59816 times.
59816 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4557 {
4558 Z_scripterrlog("bitmap->DrawTile() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4559 return;
4560 }
4561
4562 59816 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
4563
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 59816 times.
59816 if ( refbmp == NULL ) return;
4564
4565 59816 int32_t xscale=sdci[8]/10000;
4566 59816 int32_t yscale=sdci[9]/10000;
4567 59816 int32_t rx = sdci[10]/10000;
4568 59816 int32_t ry = sdci[11]/10000;
4569 59816 float rotation=sdci[12]/10000;
4570 59816 int32_t flip=(sdci[13]/10000)&3;
4571 59816 bool transparency=sdci[14]!=0;
4572 59816 int32_t opacity=sdci[15]/10000;
4573 59816 int32_t color=sdci[7]/10000;
4574
4575 59816 int32_t x1=sdci[2]/10000;
4576 59816 int32_t y1=sdci[3]/10000;
4577
4578
4579 //don't scale if it's not safe to do so
4580 59816 bool canscale = true;
4581
4582
2/4
✓ Branch 0 taken 59816 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 59816 times.
59816 if(xscale==0||yscale==0)
4583 {
4584 return;
4585 }
4586
4587
3/4
✓ Branch 0 taken 906 times.
✓ Branch 1 taken 58910 times.
✓ Branch 2 taken 906 times.
✗ Branch 3 not taken.
59816 if(xscale<0||yscale<0)
4588 58910 canscale = false; //default size
4589
4590
2/4
✓ Branch 0 taken 59816 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 59816 times.
59816 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4591
4592
4/4
✓ Branch 0 taken 906 times.
✓ Branch 1 taken 58910 times.
✓ Branch 2 taken 4608 times.
✓ Branch 3 taken 54302 times.
59816 if((xscale>0 && yscale>0) || rotation) //scaled or rotated
4593 {
4594 5514 BITMAP* pbitty = script_drawing_commands.AquireSubBitmap(w*16, h*16);
4595
4596
1/2
✓ Branch 0 taken 5514 times.
✗ Branch 1 not taken.
5514 if(transparency) //transparency
4597 {
4598 5514 TileHelper::OverTile(pbitty, (sdci[4]/10000), 0, 0, w, h, color, flip);
4599 5514 }
4600 else //no transparency
4601 {
4602 TileHelper::OldPutTile(pbitty, (sdci[4]/10000), 0, 0, w, h, color, flip);
4603 }
4604
4605
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 906 times.
5514 if(rotation != 0)
4606 {
4607 //low negative values indicate no anchor-point rotation
4608
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
4608 if(rx>-777||ry>-777)
4609 {
4610 int32_t xy[2];
4611 4608 fixed ra1=itofix(sdci[12]%10000)/10000;
4612 4608 fixed ra2=itofix(sdci[12]/10000);
4613 4608 fixed ra=ra1+ra2;
4614 4608 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
4615 4608 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
4616 4608 x1=xy[0];
4617 4608 y1=xy[1];
4618 4608 }
4619
4620
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 if(canscale) //scale first
4621 {
4622 //damnit all, .. fixme.
4623 BITMAP* tempbit = create_bitmap_ex(8, xscale>512?512:xscale, yscale>512?512:yscale);
4624 clear_bitmap(tempbit);
4625
4626 stretch_sprite(tempbit, pbitty, 0, 0, xscale, yscale);
4627
4628 if(opacity < 128)
4629 {
4630 clear_bitmap(prim_bmp);
4631 rotate_sprite(prim_bmp, tempbit, 0, 0, degrees_to_fixed(rotation));
4632 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
4633 }
4634 else
4635 {
4636 rotate_sprite(refbmp, tempbit, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
4637 }
4638
4639 destroy_bitmap(tempbit);
4640 }
4641 else //no scale
4642 {
4643
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 if(opacity < 128)
4644 {
4645 clear_bitmap(prim_bmp);
4646 rotate_sprite(prim_bmp, pbitty, 0, 0, degrees_to_fixed(rotation));
4647 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4648 }
4649 else
4650 {
4651 4608 rotate_sprite(refbmp, pbitty, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
4652 }
4653 }
4654 4608 }
4655 else //scale only
4656 {
4657
1/2
✓ Branch 0 taken 906 times.
✗ Branch 1 not taken.
906 if(canscale)
4658 {
4659
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
906 if(opacity<128)
4660 {
4661 clear_bitmap(prim_bmp);
4662 stretch_sprite(prim_bmp, pbitty, 0, 0, xscale, yscale);
4663 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4664 }
4665 else
4666 {
4667 906 stretch_sprite(refbmp, pbitty, x1+xoffset, y1+yoffset, xscale, yscale);
4668 }
4669 906 }
4670 else //error -do not scale
4671 {
4672 if(opacity<128)
4673 {
4674 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4675 }
4676 else
4677 {
4678 draw_sprite(refbmp, pbitty, x1+xoffset, y1+yoffset);
4679 }
4680 }
4681 }
4682
4683 5514 script_drawing_commands.ReleaseSubBitmap(pbitty);
4684
4685 5514 }
4686 else // no scale or rotation
4687 {
4688
2/2
✓ Branch 0 taken 45964 times.
✓ Branch 1 taken 8338 times.
54302 if(transparency)
4689 {
4690
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45964 times.
45964 if(opacity<=127)
4691 TileHelper::OverTileTranslucent(refbmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip, opacity);
4692 else
4693 45964 TileHelper::OverTile(refbmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip);
4694 45964 }
4695 else
4696 {
4697
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8338 times.
8338 if(opacity<=127)
4698 TileHelper::PutTileTranslucent(refbmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip, opacity);
4699 else
4700 8338 TileHelper::OldPutTile(refbmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip);
4701 }
4702 }
4703 59816 }
4704
4705 void bmp_do_drawtilecloakedr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4706 {
4707 //sdci[1]=layer
4708 //sdci[2]=x
4709 //sdci[3]=y
4710 //sdci[4]=tile
4711 //sdci[5]=tile width
4712 //sdci[6]=tile height
4713 //sdci[7]=flip
4714 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4715
4716 int32_t w = sdci[5]/10000;
4717 int32_t h = sdci[6]/10000;
4718
4719 if(w < 1 || h < 1 || h > 20 || w > 20)
4720 {
4721 return;
4722 }
4723
4724 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4725 {
4726 Z_scripterrlog("bitmap->DrawTileCloaked() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4727 return;
4728 }
4729
4730 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
4731 if ( refbmp == NULL ) return;
4732
4733 int32_t flip=(sdci[7]/10000)&3;
4734
4735 int32_t x1=sdci[2]/10000;
4736 int32_t y1=sdci[3]/10000;
4737
4738 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4739
4740 TileHelper::OverTileCloaked(refbmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, flip);
4741 }
4742
4743
4744 824 void bmp_do_drawcombor(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4745 {
4746 //sdci[1]=layer
4747 //sdci[2]=x
4748 //sdci[3]=y
4749 //sdci[4]=combo
4750 //sdci[5]=tile width
4751 //sdci[6]=tile height
4752 //sdci[7]=color (cset)
4753 //sdci[8]=scale x
4754 //sdci[9]=scale y
4755 //sdci[10]=rotation anchor x
4756 //sdci[11]=rotation anchor y
4757 //sdci[12]=rotation angle
4758 //sdci[13]=frame
4759 //sdci[14]=flip
4760 //sdci[15]=transparency
4761 //sdci[16]=opacity
4762 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4763 824 int32_t w = sdci[5]/10000;
4764 824 int32_t h = sdci[6]/10000;
4765
4766
4/8
✓ Branch 0 taken 824 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 824 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 824 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 824 times.
824 if(w<1||h<1||h>20||w>20)
4767 {
4768 return;
4769 }
4770
4771
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 824 times.
824 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4772 {
4773 Z_scripterrlog("bitmap->DrawCombo() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4774 return;
4775 }
4776
4777 824 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
4778
1/2
✓ Branch 0 taken 824 times.
✗ Branch 1 not taken.
824 if ( refbmp == NULL ) return;
4779 824 int32_t cmb = (sdci[4]/10000);
4780
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 824 times.
824 if((unsigned)cmb >= MAXCOMBOS)
4781 {
4782 Z_scripterrlog("DrawCombo() cannot draw combo '%d', as it is out of bounds.\n", cmb);
4783 return;
4784 }
4785
4786 824 int32_t xscale=sdci[8]/10000;
4787 824 int32_t yscale=sdci[9]/10000;
4788 824 int32_t rx = sdci[10]/10000; //these work now
4789 824 int32_t ry = sdci[11]/10000; //these work now
4790 824 float rotation=sdci[12]/10000;
4791
4792 824 bool transparency=sdci[15]!=0;
4793 824 int32_t opacity=sdci[16]/10000;
4794 824 int32_t color=sdci[7]/10000;
4795 824 int32_t x1=sdci[2]/10000;
4796 824 int32_t y1=sdci[3]/10000;
4797
4798 824 auto& c = GET_DRAWING_COMBO(cmb);
4799 824 int32_t tiletodraw = combo_tile(c, x1, y1);
4800 824 int32_t flip = ((sdci[14]/10000) & 3) ^ c.flip;
4801 824 int32_t skiprows=c.skipanimy;
4802
4803
4804 //don't scale if it's not safe to do so
4805 824 bool canscale = true;
4806
4807
2/4
✓ Branch 0 taken 824 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 824 times.
824 if(xscale==0||yscale==0)
4808 {
4809 return;
4810 }
4811
4812
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 824 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
824 if(xscale<0||yscale<0)
4813 824 canscale = false; //default size
4814
4815
2/4
✓ Branch 0 taken 824 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 824 times.
824 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4816
4817
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 824 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 824 times.
824 if((xscale>0 && yscale>0) || rotation) //scaled or rotated
4818 {
4819 BITMAP* pbitty = script_drawing_commands.AquireSubBitmap(w*16, h*16); //-pbitty in the hisouse. :D
4820
4821 if(transparency)
4822 {
4823 TileHelper::OverTile(pbitty, tiletodraw, 0, 0, w, h, color, flip, skiprows);
4824 }
4825 else //no transparency
4826 {
4827 TileHelper::OldPutTile(pbitty, tiletodraw, 0, 0, w, h, color, flip, skiprows);
4828 }
4829
4830 if(rotation != 0) // rotate
4831 {
4832 //fixed point sucks ;0
4833 if(rx>-777||ry>-777) //set the rotation anchor and rotate around that
4834 {
4835 int32_t xy[2];
4836 fixed ra1=itofix(sdci[12]%10000)/10000;
4837 fixed ra2=itofix(sdci[12]/10000);
4838 fixed ra=ra1+ra2;
4839 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
4840 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
4841 x1=xy[0];
4842 y1=xy[1];
4843 }
4844
4845 if(canscale) //scale first
4846 {
4847 BITMAP* tempbit = create_bitmap_ex(8, xscale>512?512:xscale, yscale>512?512:yscale);
4848 clear_bitmap(tempbit);
4849
4850 stretch_sprite(tempbit, pbitty, 0, 0, xscale, yscale);
4851
4852 if(opacity < 128)
4853 {
4854 clear_bitmap(prim_bmp);
4855 rotate_sprite(prim_bmp, tempbit, 0, 0, degrees_to_fixed(rotation));
4856 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4857 }
4858 else
4859 {
4860 rotate_sprite(refbmp, tempbit, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
4861 }
4862
4863 destroy_bitmap(tempbit);
4864 }
4865 else //no scale
4866 {
4867 if(opacity < 128)
4868 {
4869 clear_bitmap(prim_bmp);
4870 rotate_sprite(prim_bmp, pbitty, 0, 0, degrees_to_fixed(rotation));
4871 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4872 }
4873 else
4874 {
4875 rotate_sprite(refbmp, pbitty, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
4876 }
4877 }
4878 }
4879 else //scale only
4880 {
4881 if(canscale)
4882 {
4883 if(opacity<128)
4884 {
4885 clear_bitmap(prim_bmp);
4886 stretch_sprite(prim_bmp, pbitty, 0, 0, xscale, yscale);
4887 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4888 }
4889 else
4890 {
4891 stretch_sprite(refbmp, pbitty, x1+xoffset, y1+yoffset, xscale, yscale);
4892 }
4893 }
4894 else //error -do not scale
4895 {
4896 if(opacity<128)
4897 {
4898 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4899 }
4900 else
4901 {
4902 draw_sprite(refbmp, pbitty, x1+xoffset, y1+yoffset);
4903 }
4904 }
4905 }
4906
4907 script_drawing_commands.ReleaseSubBitmap(pbitty); //rap sucks
4908 }
4909 else // no scale or rotation
4910 {
4911
1/2
✓ Branch 0 taken 824 times.
✗ Branch 1 not taken.
824 if(transparency)
4912 {
4913
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 824 times.
824 if(opacity<=127)
4914 TileHelper::OverTileTranslucent(refbmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, opacity, skiprows);
4915 else
4916 824 TileHelper::OverTile(refbmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, skiprows);
4917 824 }
4918 else
4919 {
4920 if(opacity<=127)
4921 TileHelper::PutTileTranslucent(refbmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, opacity, skiprows);
4922 else
4923 TileHelper::OldPutTile(refbmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, skiprows);
4924 }
4925 }
4926 824 }
4927
4928
4929 void bmp_do_drawcombocloakedr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4930 {
4931 //sdci[1]=layer
4932 //sdci[2]=x
4933 //sdci[3]=y
4934 //sdci[4]=combo
4935 //sdci[5]=tile width
4936 //sdci[6]=tile height
4937 //sdci[7]=flip
4938 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4939
4940 int32_t w = sdci[5]/10000;
4941 int32_t h = sdci[6]/10000;
4942
4943 if(w<1||h<1||h>20||w>20)
4944 {
4945 return;
4946 }
4947
4948 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4949 {
4950 Z_scripterrlog("bitmap->DrawComboCloaked() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4951 return;
4952 }
4953
4954 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
4955 if ( refbmp == NULL ) return;
4956 int32_t cmb = (sdci[4]/10000);
4957 if((unsigned)cmb >= MAXCOMBOS)
4958 {
4959 Z_scripterrlog("DrawComboCloaked() cannot draw combo '%d', as it is out of bounds.\n", cmb);
4960 return;
4961 }
4962
4963 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4964
4965 int32_t x1=sdci[2]/10000;
4966 int32_t y1=sdci[3]/10000;
4967
4968 auto& c = GET_DRAWING_COMBO(cmb);
4969 int32_t tiletodraw = combo_tile(c, x1, y1);
4970 int32_t flip = ((sdci[7]/10000) & 3) ^ c.flip;
4971 int32_t skiprows=c.skipanimy;
4972
4973 TileHelper::OverTileCloaked(refbmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, flip, skiprows);
4974 }
4975
4976
4977 168443 void bmp_do_fasttiler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4978 {
4979 /* layer, x, y, tile, color opacity */
4980 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4981
4982 168443 int32_t opacity = sdci[6]/10000;
4983
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 168443 times.
168443 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4984 {
4985 Z_scripterrlog("bitmap->FastTile() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4986 return;
4987 }
4988 168443 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
4989
1/2
✓ Branch 0 taken 168443 times.
✗ Branch 1 not taken.
168443 if ( refbmp == NULL ) return;
4990
4991
2/4
✓ Branch 0 taken 168443 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 168443 times.
✗ Branch 3 not taken.
168443 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4992
4993 168443 int x = xoffset+(sdci[2]/10000);
4994 168443 int y = yoffset+(sdci[3]/10000);
4995
4996
2/2
✓ Branch 0 taken 11131 times.
✓ Branch 1 taken 157312 times.
168443 if(opacity < 128)
4997 11131 overtiletranslucent16(refbmp, sdci[4]/10000, x, y, sdci[5]/10000, 0, opacity);
4998 else
4999 157312 overtile16(refbmp, sdci[4]/10000, x, y, sdci[5]/10000, 0);
5000 168443 }
5001
5002 19821648 void do_bmpwritetile(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5003 {
5004 /* layer, x, y, tile, is8bit, mask */
5005 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5006
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19821648 times.
19821648 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5007 {
5008 Z_scripterrlog("bitmap->WriteTile() wanted to read from an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5009 return;
5010 }
5011 19821648 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
5012
1/2
✓ Branch 0 taken 19821648 times.
✗ Branch 1 not taken.
19821648 if ( refbmp == NULL ) return;
5013
5014
2/4
✓ Branch 0 taken 19821648 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19821648 times.
✗ Branch 3 not taken.
19821648 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
5015
5016 19821648 int32_t x = (sdci[2]/10000), y = (sdci[3]/10000), tl = (sdci[4]/10000);
5017 19821648 bool is8bit = sdci[5]!=0, mask = sdci[6]!=0;
5018
5019 19821648 write_tile(newtilebuf, refbmp, tl, x+xoffset, y+yoffset, is8bit, mask);
5020 19821648 }
5021
5022 void do_bmpdither(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5023 {
5024 /* layer, mask, color, ditherType, ditherArg */
5025 //sdci[2] Mask Bitmap Pointer
5026 //sdci[3] Color
5027 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5028 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5029 {
5030 Z_scripterrlog("bitmap->Dither() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5031 return;
5032 }
5033 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
5034 if ( refbmp == NULL ) return;
5035 if ( sdci[2] <= 0 )
5036 {
5037 Z_scripterrlog("bitmap->Dither() wanted to read from an invalid bitmap id: %d. Aborting.\n", sdci[2]);
5038 return;
5039 }
5040 BITMAP *mask = FFCore.GetScriptBitmap(sdci[2]);
5041 if ( mask == NULL ) return;
5042
5043 int32_t dType = sdci[4] / 10000L;
5044 if(dType < 0 || dType >= dithMax)
5045 {
5046 Z_scripterrlog("bitmap->Dither() used an invalid dither type: %d. Aborting.\n", dType);
5047 return;
5048 }
5049
5050 ditherblit(refbmp, mask, byte(sdci[3]/10000L), dType, sdci[5]/10000L);
5051 }
5052
5053 7323 void do_bmpreplcol(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5054 {
5055 /* layer, shift, startcol, endcol */
5056 //sdci[2] NewCol
5057 //sdci[3] StartCol
5058 //sdci[4] EndCol
5059 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5060
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7323 times.
7323 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5061 {
5062 Z_scripterrlog("bitmap->ReplaceColors() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5063 return;
5064 }
5065 7323 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
5066
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7323 times.
7323 if ( refbmp == NULL ) return;
5067 7323 replColor(refbmp, sdci[2]/10000L, sdci[3]/10000L, sdci[4]/10000L, false);
5068 7323 }
5069
5070 void do_bmpshiftcol(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5071 {
5072 /* layer, shift, startcol, endcol */
5073 //sdci[2] ShiftAmount
5074 //sdci[3] StartCol
5075 //sdci[4] EndCol
5076 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5077 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5078 {
5079 Z_scripterrlog("bitmap->ShiftColors() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5080 return;
5081 }
5082 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
5083 if ( refbmp == NULL ) return;
5084 replColor(refbmp, sdci[2]/10000L, sdci[3]/10000L, sdci[4]/10000L, true);
5085 }
5086
5087 906 void do_bmpmaskdraw(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5088 {
5089 /* layer, mask, color */
5090 //sdci[2] Mask Bitmap Pointer
5091 //sdci[3] Color
5092 //sdci[4] start mask color
5093 //sdci[5] end mask color
5094 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5095 906 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
5096
1/2
✓ Branch 0 taken 906 times.
✗ Branch 1 not taken.
906 if ( refbmp == NULL )
5097 {
5098 Z_scripterrlog("bitmap->MaskDraw() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5099 return;
5100 }
5101 906 BITMAP *mask = FFCore.GetScriptBitmap(sdci[2]);
5102
1/2
✓ Branch 0 taken 906 times.
✗ Branch 1 not taken.
906 if ( mask == NULL )
5103 {
5104 Z_scripterrlog("bitmap->MaskDraw() wanted to read from an invalid bitmap id: %d. Aborting.\n", sdci[2]);
5105 return;
5106 }
5107 906 auto fillcol = sdci[3]/10000L;
5108
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
906 if(unsigned(fillcol) > 0xFF) return; //invalid color, nothing to draw
5109 906 auto startcol = vbound(sdci[4]/10000L,0x00,0xFF);
5110 906 auto endcol = vbound(sdci[5]/10000L,0x00,0xFF);
5111 906 mask_colorfill(refbmp, mask, fillcol, startcol, endcol);
5112 906 }
5113
5114 void do_bmpmaskblit(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5115 {
5116 /* layer, mask, color */
5117 //sdci[2] Mask Bitmap Pointer
5118 //sdci[3] Pattern Bitmap
5119 //sdci[4] bool 'pattern repeats'
5120 //sdci[5] start mask color
5121 //sdci[6] end mask color
5122 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5123 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
5124 if ( refbmp == NULL )
5125 {
5126 Z_scripterrlog("bitmap->MaskDraw() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5127 return;
5128 }
5129 BITMAP *mask = FFCore.GetScriptBitmap(sdci[2]);
5130 if ( mask == NULL )
5131 {
5132 Z_scripterrlog("bitmap->MaskDraw() wanted to read from an invalid bitmap (mask) id: %d. Aborting.\n", sdci[2]);
5133 return;
5134 }
5135 BITMAP *pattern = FFCore.GetScriptBitmap(sdci[3]);
5136 if ( pattern == NULL )
5137 {
5138 Z_scripterrlog("bitmap->MaskDraw() wanted to read from an invalid bitmap (pattern) id: %d. Aborting.\n", sdci[3]);
5139 return;
5140 }
5141 bool repeats = sdci[4]!=0;
5142 auto startcol = vbound(sdci[5]/10000L,0x00,0xFF);
5143 auto endcol = vbound(sdci[6]/10000L,0x00,0xFF);
5144 mask_blit(refbmp, mask, pattern, repeats, startcol, endcol);
5145 }
5146
5147 32636464 void bmp_do_fastcombor(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5148 {
5149 /* layer, x, y, tile, color opacity */
5150 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5151 32636464 int32_t opacity = sdci[6] / 10000;
5152 32636464 int32_t x1 = sdci[2] / 10000;
5153 32636464 int32_t y1 = sdci[3] / 10000;
5154 32636464 int32_t index = sdci[4]/10000;
5155
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32636464 times.
32636464 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5156 {
5157 Z_scripterrlog("bitmap->FastCombo() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5158 return;
5159 }
5160 32636464 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
5161
1/2
✓ Branch 0 taken 32636464 times.
✗ Branch 1 not taken.
32636464 if ( refbmp == NULL ) return;
5162 32636464 int32_t cmb = (sdci[4]/10000);
5163
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32636464 times.
32636464 if((unsigned)cmb >= MAXCOMBOS)
5164 {
5165 Z_scripterrlog("FastCombo() cannot draw combo '%d', as it is out of bounds.\n", cmb);
5166 return;
5167 }
5168
5169
2/4
✓ Branch 0 taken 32636464 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 32636464 times.
✗ Branch 3 not taken.
32636464 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
5170
5171 32636464 int x = xoffset+x1;
5172 32636464 int y = yoffset+y1;
5173
5174
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32636464 times.
32636464 if(opacity < 128)
5175 {
5176 overcomboblocktranslucent(refbmp, x, y, cmb, sdci[5]/10000, 1, 1, 128);
5177
5178 }
5179 else
5180 {
5181 32636464 overcomboblock(refbmp, x, y, cmb, sdci[5]/10000, 1, 1);
5182 }
5183 32636464 }
5184
5185
5186
5187 void bmp_do_drawcharr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5188 {
5189 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5190 {
5191 Z_scripterrlog("bitmap->DrawCharacter() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5192 return;
5193 }
5194 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
5195 if ( refbmp == NULL ) return;
5196
5197 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
5198
5199 //broken 2.50.2 and earlier drawcharacter()
5200 if ( get_qr(qr_BROKENCHARINTDRAWING) )
5201 {
5202 //sdci[1]=layer
5203 //sdci[2]=x
5204 //sdci[3]=y
5205 //sdci[4]=font
5206 //sdci[5]=color
5207 //sdci[6]=bg color
5208 //sdci[7]=strech x (width)
5209 //sdci[8]=stretch y (height)
5210 //sdci[9]=char
5211 //sdci[10]=opacity
5212 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5213
5214 int32_t x=sdci[2]/10000;
5215 int32_t y=sdci[3]/10000;
5216 int32_t font_index=sdci[4]/10000;
5217 int32_t color=sdci[5]/10000;
5218 int32_t bg_color=sdci[6]/10000; //-1 = transparent
5219 int32_t w=sdci[7]/10000;
5220 int32_t h=sdci[8]/10000;
5221 char glyph=char(sdci[9]/10000);
5222 int32_t opacity=sdci[10]/10000;
5223
5224 //safe check
5225 if(bg_color < -1) bg_color = -1;
5226
5227 if(w>512) w=512; //w=vbound(w,0,512);
5228
5229 if(h>512) h=512; //h=vbound(h,0,512);
5230
5231 //undone
5232 if(w>0&&h>0)//stretch the character
5233 {
5234 BITMAP *pbmp = script_drawing_commands.GetSmallTextureBitmap(1,1);
5235
5236 if(opacity < 128)
5237 {
5238 if(w>128||h>128)
5239 {
5240 clear_bitmap(prim_bmp);
5241
5242 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5243 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
5244 draw_trans_sprite(refbmp, prim_bmp, x+xoffset, y+yoffset);
5245 }
5246 else //this is faster
5247 {
5248 BITMAP *pbmp2 = script_drawing_commands.AquireSubBitmap(w,h);
5249
5250 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5251 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
5252 draw_trans_sprite(refbmp, pbmp2, x+xoffset, y+yoffset);
5253
5254 script_drawing_commands.ReleaseSubBitmap(pbmp2);
5255 }
5256 }
5257 else // no opacity
5258 {
5259 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5260 stretch_sprite(refbmp, pbmp, x+xoffset, y+yoffset, w, h);
5261 }
5262
5263 }
5264 else //no stretch
5265 {
5266 if(opacity < 128)
5267 {
5268 BITMAP *pbmp = create_sub_bitmap(prim_bmp,0,0,16,16);
5269 clear_bitmap(pbmp);
5270
5271 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5272 draw_trans_sprite(refbmp, pbmp, x+xoffset, y+yoffset);
5273
5274 destroy_bitmap(pbmp);
5275 }
5276 else // no opacity
5277 {
5278 textprintf_ex(refbmp, get_zc_font(font_index), x+xoffset, y+yoffset, color, bg_color, "%c", glyph);
5279 }
5280 }
5281 }
5282
5283 else //2.53.0 fixed version and later.
5284 {
5285
5286 //sdci[1]=layer
5287 //sdci[2]=x
5288 //sdci[3]=y
5289 //sdci[4]=font
5290 //sdci[5]=color
5291 //sdci[6]=bg color
5292 //sdci[7]=strech x (width)
5293 //sdci[8]=stretch y (height)
5294 //sdci[9]=char
5295 //sdci[10]=opacity
5296
5297 int32_t x=sdci[2]/10000;
5298 int32_t y=sdci[3]/10000;
5299 int32_t font_index=sdci[4]/10000;
5300 int32_t color=sdci[5]/10000;
5301 int32_t bg_color=sdci[6]/10000; //-1 = transparent
5302 int32_t w=sdci[7]/10000;
5303 int32_t h=sdci[8]/10000;
5304 char glyph=char(sdci[9]/10000);
5305 int32_t opacity=sdci[10]/10000;
5306
5307 //safe check
5308 if(bg_color < -1) bg_color = -1;
5309
5310 if(w>512) w=512; //w=vbound(w,0,512);
5311
5312 if(h>512) h=512; //h=vbound(h,0,512);
5313
5314 //undone
5315 if(w>0&&h>0)//stretch the character
5316 {
5317 BITMAP *pbmp = script_drawing_commands.GetSmallTextureBitmap(1,1);
5318
5319 if(opacity < 128)
5320 {
5321 if(w>128||h>128)
5322 {
5323 clear_bitmap(prim_bmp);
5324
5325 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5326 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
5327 draw_trans_sprite(refbmp, prim_bmp, x+xoffset, y+yoffset);
5328 }
5329 else //this is faster
5330 {
5331 BITMAP *pbmp2 = script_drawing_commands.AquireSubBitmap(w,h);
5332
5333 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5334 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
5335 draw_trans_sprite(refbmp, pbmp2, x+xoffset, y+yoffset);
5336
5337 script_drawing_commands.ReleaseSubBitmap(pbmp2);
5338 }
5339 }
5340 else // no opacity
5341 {
5342 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5343 stretch_sprite(refbmp, pbmp, x+xoffset, y+yoffset, w, h);
5344 }
5345
5346 }
5347 else //no stretch
5348 {
5349 if(opacity < 128)
5350 {
5351 BITMAP *pbmp = create_sub_bitmap(prim_bmp,0,0,16,16);
5352 clear_bitmap(pbmp);
5353
5354 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5355 draw_trans_sprite(refbmp, pbmp, x+xoffset, y+yoffset);
5356
5357 destroy_bitmap(pbmp);
5358 }
5359 else // no opacity
5360 {
5361 textprintf_ex(refbmp, get_zc_font(font_index), x+xoffset, y+yoffset, color, bg_color, "%c", glyph);
5362 }
5363 }
5364
5365 }
5366
5367 }
5368
5369
5370 void bmp_do_drawintr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5371 {
5372 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5373 {
5374 Z_scripterrlog("bitmap->DrawInteger() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5375 return;
5376 }
5377 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
5378 if ( refbmp == NULL ) return;
5379
5380 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
5381
5382 //broken 2.50.2 and earlier drawinteger()
5383 if ( get_qr(qr_BROKENCHARINTDRAWING) )
5384 {
5385 //sdci[1]=layer
5386 //sdci[2]=x
5387 //sdci[3]=y
5388 //sdci[4]=font
5389 //sdci[5]=color
5390 //sdci[6]=bg color
5391 //sdci[7]=strech x (width)
5392 //sdci[8]=stretch y (height)
5393 //sdci[9]=integer
5394 //sdci[10]=num decimal places
5395 //sdci[11]=opacity
5396 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5397
5398 int32_t x=sdci[2]/10000;
5399 int32_t y=sdci[3]/10000;
5400 int32_t font_index=sdci[4]/10000;
5401 int32_t color=sdci[5]/10000;
5402 int32_t bg_color=sdci[6]/10000; //-1 = transparent
5403 int32_t w=sdci[7]/10000;
5404 int32_t h=sdci[8]/10000;
5405 int32_t decplace=sdci[10]/10000;
5406 int32_t opacity=sdci[11]/10000;
5407
5408 //safe check
5409 if(bg_color < -1) bg_color = -1;
5410
5411 if(w>512) w=512; //w=vbound(w,0,512);
5412
5413 if(h>512) h=512; //h=vbound(h,0,512);
5414
5415 char numbuf[15];
5416
5417 switch(decplace)
5418 {
5419 default:
5420 case 0:
5421 sprintf(numbuf,"%d",(sdci[9]/10000)); //For some reason, static casting for zero decimal places was
5422 break; //reducing the value by -1, so 8.000 printed as '7'. -Z
5423
5424 case 1:
5425 //sprintf(numbuf,"%.01f",number);
5426 sprintf(numbuf,"%.01f",(static_cast<float>(sdci[9])/10000.0f)); //Would this be slower?
5427 break;
5428
5429 case 2:
5430 //sprintf(numbuf,"%.02f",number);
5431 sprintf(numbuf,"%.02f",(static_cast<float>(sdci[9])/10000.0f));
5432 break;
5433
5434 case 3:
5435 //sprintf(numbuf,"%.03f",number);
5436 sprintf(numbuf,"%.03f",(static_cast<float>(sdci[9])/10000.0f));
5437 break;
5438
5439 case 4:
5440 //sprintf(numbuf,"%.04f",number);
5441 sprintf(numbuf,"%.04f",(static_cast<float>(sdci[9])/10000.0f));
5442 break;
5443 }
5444
5445 if(w>0&&h>0)//stretch
5446 {
5447 BITMAP *pbmp = script_drawing_commands.GetSmallTextureBitmap(1,1);
5448
5449 if(opacity < 128)
5450 {
5451 if(w>128||h>128)
5452 {
5453 clear_bitmap(prim_bmp);
5454
5455 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5456 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
5457 draw_trans_sprite(refbmp, prim_bmp, x+xoffset, y+yoffset);
5458 }
5459 else
5460 {
5461 BITMAP *pbmp2 = create_sub_bitmap(prim_bmp,0,0,w,h);
5462 clear_bitmap(pbmp2);
5463
5464 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5465 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
5466 draw_trans_sprite(refbmp, pbmp2, x+xoffset, y+yoffset);
5467
5468 destroy_bitmap(pbmp2);
5469 }
5470 }
5471 else // no opacity
5472 {
5473 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5474 stretch_sprite(refbmp, pbmp, x+xoffset, y+yoffset, w, h);
5475 }
5476
5477 }
5478 else //no stretch
5479 {
5480 if(opacity < 128)
5481 {
5482 BITMAP *pbmp = create_sub_bitmap(prim_bmp,0,0,16,16);
5483 clear_bitmap(pbmp);
5484
5485 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5486 draw_trans_sprite(refbmp, pbmp, x+xoffset, y+yoffset);
5487
5488 destroy_bitmap(pbmp);
5489 }
5490 else // no opacity
5491 {
5492 textout_ex(refbmp, get_zc_font(font_index), numbuf, x+xoffset, y+yoffset, color, bg_color);
5493 }
5494 }
5495
5496 }
5497
5498 else //2.53.0 fixed version and later.
5499 {
5500 //sdci[1]=layer
5501 //sdci[2]=x
5502 //sdci[3]=y
5503 //sdci[4]=font
5504 //sdci[5]=color
5505 //sdci[6]=bg color
5506 //sdci[7]=strech x (width)
5507 //sdci[8]=stretch y (height)
5508 //sdci[9]=integer
5509 //sdci[10]=num decimal places
5510 //sdci[11]=opacity
5511
5512 int32_t x=sdci[2]/10000;
5513 int32_t y=sdci[3]/10000;
5514 int32_t font_index=sdci[4]/10000;
5515 int32_t color=sdci[5]/10000;
5516 int32_t bg_color=sdci[6]/10000; //-1 = transparent
5517 int32_t w=sdci[7]/10000;
5518 int32_t h=sdci[8]/10000;
5519 int32_t decplace=sdci[10]/10000;
5520 int32_t opacity=sdci[11]/10000;
5521
5522 //safe check
5523 if(bg_color < -1) bg_color = -1;
5524
5525 if(w>512) w=512; //w=vbound(w,0,512);
5526
5527 if(h>512) h=512; //h=vbound(h,0,512);
5528
5529 char numbuf[15];
5530
5531 switch(decplace)
5532 {
5533 default:
5534 case 0:
5535 sprintf(numbuf,"%d",(sdci[9]/10000)); //For some reason, static casting for zero decimal places was
5536 break; //reducing the value by -1, so 8.000 printed as '7'. -Z
5537
5538 case 1:
5539 //sprintf(numbuf,"%.01f",number);
5540 sprintf(numbuf,"%.01f",(static_cast<float>(sdci[9])/10000.0f)); //Would this be slower?
5541 break;
5542
5543 case 2:
5544 //sprintf(numbuf,"%.02f",number);
5545 sprintf(numbuf,"%.02f",(static_cast<float>(sdci[9])/10000.0f));
5546 break;
5547
5548 case 3:
5549 //sprintf(numbuf,"%.03f",number);
5550 sprintf(numbuf,"%.03f",(static_cast<float>(sdci[9])/10000.0f));
5551 break;
5552
5553 case 4:
5554 //sprintf(numbuf,"%.04f",number);
5555 sprintf(numbuf,"%.04f",(static_cast<float>(sdci[9])/10000.0f));
5556 break;
5557 }
5558
5559 //FONT* font=get_zc_font(sdci[4]/10000);
5560
5561 if(w>0&&h>0)//stretch
5562 {
5563 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, text_length(get_zc_font(font_index), numbuf)+1, text_height(get_zc_font(font_index)));
5564 clear_bitmap(pbmp);
5565 //script_drawing_commands.GetSmallTextureBitmap(1,1);
5566
5567 if(opacity < 128)
5568 {
5569 if(w>128||h>128)
5570 {
5571 clear_bitmap(prim_bmp);
5572
5573 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5574 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
5575 draw_trans_sprite(refbmp, prim_bmp, x+xoffset, y+yoffset);
5576 }
5577 else
5578 {
5579 BITMAP *pbmp2 = create_sub_bitmap(prim_bmp,0,0,w,h);
5580 clear_bitmap(pbmp2);
5581
5582 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5583 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
5584 draw_trans_sprite(refbmp, pbmp2, x+xoffset, y+yoffset);
5585
5586 destroy_bitmap(pbmp2);
5587 }
5588 }
5589 else // no opacity
5590 {
5591 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5592 stretch_sprite(refbmp, pbmp, x+xoffset, y+yoffset, w, h);
5593 }
5594
5595 }
5596 else //no stretch
5597 {
5598 if(opacity < 128)
5599 {
5600 FONT* font = get_zc_font(font_index);
5601 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, text_length(font, numbuf), text_height(font));
5602 clear_bitmap(pbmp);
5603
5604 textout_ex(pbmp, font, numbuf, 0, 0, color, bg_color);
5605 draw_trans_sprite(refbmp, pbmp, x+xoffset, y+yoffset);
5606
5607 destroy_bitmap(pbmp);
5608 }
5609 else // no opacity
5610 {
5611 textout_ex(refbmp, get_zc_font(font_index), numbuf, x+xoffset, y+yoffset, color, bg_color);
5612 }
5613 }
5614 }
5615 }
5616
5617
5618 865 void bmp_do_drawstringr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5619 {
5620 //sdci[1]=layer
5621 //sdci[2]=x
5622 //sdci[3]=y
5623 //sdci[4]=font
5624 //sdci[5]=color
5625 //sdci[6]=bg color
5626 //sdci[7]=format_option
5627 //sdci[8]=string
5628 //sdci[9]=opacity
5629 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5630
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 865 times.
865 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5631 {
5632 Z_scripterrlog("bitmap->DrawString() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5633 return;
5634 }
5635
5636 865 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
5637
1/2
✓ Branch 0 taken 865 times.
✗ Branch 1 not taken.
865 if ( refbmp == NULL ) return;
5638
5639
2/4
✓ Branch 0 taken 865 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 865 times.
865 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
5640
5641 865 std::string* str = (std::string*)script_drawing_commands[i].GetPtr();
5642
5643
1/2
✓ Branch 0 taken 865 times.
✗ Branch 1 not taken.
865 if(!str)
5644 {
5645 al_trace("String pointer is null! Internal error. \n");
5646 return;
5647 }
5648
5649 865 int32_t x=sdci[2]/10000;
5650 865 int32_t y=sdci[3]/10000;
5651 865 FONT* font=get_zc_font(sdci[4]/10000);
5652 865 int32_t color=sdci[5]/10000;
5653 865 int32_t bg_color=sdci[6]/10000; //-1 = transparent
5654 865 int32_t format_type=sdci[7]/10000;
5655 865 int32_t opacity=sdci[9]/10000;
5656 //sdci[8] not needed :)
5657
5658 //safe check
5659
1/2
✓ Branch 0 taken 865 times.
✗ Branch 1 not taken.
865 if(bg_color < -1) bg_color = -1;
5660
5661
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 865 times.
865 if(opacity < 128)
5662 {
5663 int32_t width=zc_min(text_length(font, str->c_str()), 512);
5664 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, width, text_height(font));
5665 clear_bitmap(pbmp);
5666 textout_ex(pbmp, font, str->c_str(), 0, 0, color, bg_color);
5667 if(format_type == 2) // right-sided text
5668 x-=width;
5669 else if(format_type == 1) // centered text
5670 x-=width/2;
5671 draw_trans_sprite(refbmp, pbmp, x+xoffset, y+yoffset);
5672 destroy_bitmap(pbmp);
5673 }
5674 else // no opacity
5675 {
5676
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 865 times.
865 if(format_type == 2) // right-sided text
5677 {
5678 textout_right_ex(refbmp, font, str->c_str(), x+xoffset, y+yoffset, color, bg_color);
5679 }
5680
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 865 times.
865 else if(format_type == 1) // centered text
5681 {
5682 textout_centre_ex(refbmp, font, str->c_str(), x+xoffset, y+yoffset, color, bg_color);
5683 }
5684 else // standard left-sided text
5685 {
5686 865 textout_ex(refbmp, font, str->c_str(), x+xoffset, y+yoffset, color, bg_color);
5687 }
5688 }
5689 865 }
5690
5691 45504 void bmp_do_drawstringr2(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5692 {
5693 //sdci[1]=layer
5694 //sdci[2]=x
5695 //sdci[3]=y
5696 //sdci[4]=font
5697 //sdci[5]=color
5698 //sdci[6]=bg color
5699 //sdci[7]=format_option
5700 //sdci[8]=string
5701 //sdci[9]=opacity
5702 //sdci[10]=shadowtype
5703 //sdci[11]=shadow_color
5704 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5705
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45504 times.
45504 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5706 {
5707 Z_scripterrlog("bitmap->DrawString() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5708 return;
5709 }
5710
5711 45504 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
5712
1/2
✓ Branch 0 taken 45504 times.
✗ Branch 1 not taken.
45504 if ( refbmp == NULL ) return;
5713
5714
2/4
✓ Branch 0 taken 45504 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 45504 times.
45504 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
5715
5716 45504 std::string* str = (std::string*)script_drawing_commands[i].GetPtr();
5717
5718
1/2
✓ Branch 0 taken 45504 times.
✗ Branch 1 not taken.
45504 if(!str)
5719 {
5720 al_trace("String pointer is null! Internal error. \n");
5721 return;
5722 }
5723
5724 45504 int32_t x=sdci[2]/10000;
5725 45504 int32_t y=sdci[3]/10000;
5726 45504 FONT* font=get_zc_font(sdci[4]/10000);
5727 45504 int32_t color=sdci[5]/10000;
5728 45504 int32_t bg_color=sdci[6]/10000; //-1 = transparent
5729 45504 int32_t format_type=sdci[7]/10000;
5730 45504 int32_t opacity=sdci[9]/10000;
5731 45504 int32_t textstyle = sdci[10]/10000;
5732 45504 int32_t shadow_color = sdci[11]/10000;
5733 //sdci[8] not needed :)
5734
5735 //safe check
5736
1/2
✓ Branch 0 taken 45504 times.
✗ Branch 1 not taken.
45504 if(bg_color < -1) bg_color = -1;
5737
5738
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45504 times.
45504 if(opacity < 128)
5739 {
5740 int32_t width=zc_min(text_length(font, str->c_str()), 512);
5741 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, width, text_height(font));
5742 clear_bitmap(pbmp);
5743 textout_styled_aligned_ex(pbmp, font, str->c_str(), 0, 0, textstyle, sstaLEFT, color, shadow_color, bg_color);
5744 if(format_type == 2) // right-sided text
5745 x-=width;
5746 else if(format_type == 1) // centered text
5747 x-=width/2;
5748 draw_trans_sprite(refbmp, pbmp, x+xoffset, y+yoffset);
5749 destroy_bitmap(pbmp);
5750 }
5751 else // no opacity
5752 {
5753 45504 textout_styled_aligned_ex(refbmp, font, str->c_str(), x+xoffset, y+yoffset, textstyle, format_type, color, shadow_color, bg_color);
5754 }
5755 45504 }
5756
5757 325125 void bmp_do_clearr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5758 {
5759
1/2
✓ Branch 0 taken 325125 times.
✗ Branch 1 not taken.
325125 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5760 {
5761 Z_scripterrlog("bitmap->Clear() wanted to use to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5762 return;
5763 }
5764 325125 int32_t bitid = sdci[DRAWCMD_BMP_TARGET];
5765 325125 auto& usr_bitmap = scb.get(bitid);
5766
1/2
✓ Branch 0 taken 325125 times.
✗ Branch 1 not taken.
325125 if (usr_bitmap.u_bmp)
5767 325125 clear_bitmap(usr_bitmap.u_bmp);
5768 325125 }
5769
5770 2790 void bmp_do_clearcolorr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5771 {
5772 //sdci[1]=layer
5773 //sdci[2]=color
5774 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5775 2790 int32_t pal_color = sdci[2]/10000;
5776
1/2
✓ Branch 0 taken 2790 times.
✗ Branch 1 not taken.
2790 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5777 {
5778 Z_scripterrlog("bitmap->ClearToColor() wanted to use to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5779 return;
5780 }
5781 2790 int32_t bitid = sdci[DRAWCMD_BMP_TARGET];
5782 2790 auto& usr_bitmap = scb.get(bitid);
5783
1/2
✓ Branch 0 taken 2790 times.
✗ Branch 1 not taken.
2790 if (usr_bitmap.u_bmp)
5784 2790 clear_to_color(usr_bitmap.u_bmp, pal_color);
5785 2790 }
5786
5787
5788 34653 void bmp_do_regenr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5789 {
5790 //sdci[1]=layer
5791 34653 int32_t h = sdci[3]/10000;
5792 34653 int32_t w = sdci[2]/10000;
5793
1/2
✓ Branch 0 taken 34653 times.
✗ Branch 1 not taken.
34653 if ( get_qr(qr_OLDCREATEBITMAP_ARGS) )
5794 {
5795 //flip height and width
5796 h = h ^ w;
5797 w = h ^ w;
5798 h = h ^ w;
5799 }
5800 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5801 //Z_scripterrlog("bitmap->Create() pointer is: %d\n", sdci[DRAWCMD_BMP_TARGET]);
5802
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 34653 times.
34653 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5803 {
5804 Z_scripterrlog("bitmap->Create() wanted to use to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5805 return;
5806 }
5807 34653 int32_t bitid = sdci[DRAWCMD_BMP_TARGET];
5808 34653 auto& usr_bmp = scb.get(bitid);
5809
2/2
✓ Branch 0 taken 34528 times.
✓ Branch 1 taken 125 times.
34653 if ( usr_bmp.u_bmp )
5810 34528 destroy_bitmap(usr_bmp.u_bmp);
5811 34653 usr_bmp.u_bmp = create_bitmap_ex(8,w,h);
5812
5813 34653 usr_bmp.width = w;
5814 34653 usr_bmp.height = h;
5815 34653 }
5816
5817 void bmp_do_readr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5818 {
5819 //sdci[1]=layer
5820 //sdci[2]=filename
5821 //sdci[3]=y
5822 //sdci[4]=font
5823 //sdci[5]=color
5824 //sdci[6]=bg color
5825 //sdci[7]=format_option
5826 //sdci[8]=string
5827 //sdci[9]=opacity
5828 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5829 //Z_scripterrlog("bitmap->Read() pointer is: %d\n", sdci[DRAWCMD_BMP_TARGET]);
5830 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5831 {
5832 Z_scripterrlog("bitmap->Read() wanted to use to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5833 return;
5834 }
5835 int32_t bitid = sdci[DRAWCMD_BMP_TARGET];
5836 auto& usr_bitmap = scb.get(bitid);
5837 usr_bitmap.destroy();
5838
5839 std::string* str = (std::string*)script_drawing_commands[i].GetPtr();
5840
5841 if(!str)
5842 {
5843 al_trace("String pointer is null! Internal error. \n");
5844 return;
5845 }
5846
5847 PALETTE tempPal;
5848 get_palette(tempPal);
5849 if ( checkPath(str->c_str(), false) )
5850 {
5851 usr_bitmap.u_bmp = load_bitmap(str->c_str(), tempPal);
5852 usr_bitmap.width = usr_bitmap.u_bmp->w;
5853 usr_bitmap.height = usr_bitmap.u_bmp->h;
5854 if ( !usr_bitmap.u_bmp )
5855 {
5856 Z_scripterrlog("Failed to load image file %s.\nMaking a blank bitmap on the pointer.\n", str->c_str());
5857 }
5858 else
5859 {
5860 zprint("Read image file %s\n",str->c_str());
5861 }
5862 }
5863 else
5864 {
5865 Z_scripterrlog("Failed to load image file: %s. File not found. Creating a blank bitmap on the pointer.\n", str->c_str());
5866 usr_bitmap.u_bmp = create_bitmap_ex(8,256,176);
5867 clear_bitmap(usr_bitmap.u_bmp);
5868 }
5869 }
5870
5871
5872
5873 void bmp_do_writer(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5874 {
5875 //sdci[1]=layer
5876 //sdci[2]=filename
5877 //sdci[3]=y
5878 //sdci[4]=font
5879 //sdci[5]=color
5880 //sdci[6]=bg color
5881 //sdci[7]=format_option
5882 //sdci[8]=string
5883 //sdci[9]=opacity
5884 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5885 //Z_scripterrlog("bitmap->Write() pointer is: %d\n", sdci[DRAWCMD_BMP_TARGET]);
5886
5887 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5888 {
5889 Z_scripterrlog("bitmap->Write() wanted to use to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5890 return;
5891 }
5892 int32_t bitid = sdci[DRAWCMD_BMP_TARGET];
5893 auto& usr_bitmap = scb.get(bitid);
5894 if (!usr_bitmap.u_bmp)
5895 {
5896 Z_scripterrlog("Tried to write from an invalid bitmap pointer %d. Aborting. \n", sdci[DRAWCMD_BMP_TARGET]);
5897 return;
5898 }
5899
5900 bool overwrite = (sdci[3] != 0);
5901 std::string* str = (std::string*)script_drawing_commands[i].GetPtr();
5902
5903 if(!str)
5904 {
5905 al_trace("String pointer is null! Internal error. \n");
5906 return;
5907 }
5908
5909 //char *cptr = new char[str->size()+1]; // +1 to account for \0 byte
5910 //std::strncpy(cptr, str->c_str(), str->size());
5911 //Z_scripterrlog("bitmap->Write extension matches ? : %s\n!", (FFCore.checkExtension(str->c_str(), ".png")) ? "true" : "false");
5912 //Z_scripterrlog("Trying to write filename %s\n", cptr);
5913 if
5914 (
5915 ( (FFCore.checkExtension(*str, "")) ) ||
5916 ( !(FFCore.checkExtension(*str, ".png")) && !(FFCore.checkExtension(*str, ".gif")) && !(FFCore.checkExtension(*str, ".bmp"))
5917 && !(FFCore.checkExtension(*str, ".pcx")) && !(FFCore.checkExtension(*str, ".tga")) )
5918 )
5919 {
5920 Z_scripterrlog("No extension, or invalid extension provided for writing bitmap file %s. Could not write the file.\nValid types are .png, .gif, .pcx, .tgx, and .bmp. Aborting.\n",str->c_str());
5921 }
5922 else if ( overwrite || (!checkPath(str->c_str(), false)) )
5923 {
5924 if(make_dirs_for_file(*str))
5925 {
5926 save_bitmap(str->c_str(), usr_bitmap.u_bmp, RAMpal);
5927 if(checkPath(str->c_str(), false))
5928 {
5929 zprint("Wrote image file %s\n",str->c_str());
5930 }
5931 else
5932 {
5933 Z_scripterrlog("Failed to create file '%s'\n",str->c_str());
5934 }
5935 }
5936 else
5937 {
5938 Z_scripterrlog("Cannot write file '%s' because the directory does not exist, and could not be created.\n", str->c_str());
5939 }
5940 }
5941 else Z_scripterrlog("Cannot write file '%s' because the file already exists in the specified path.\n", str->c_str());
5942 }
5943
5944
5945 void bmp_do_drawquadr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5946 {
5947 //sdci[1]=layer
5948 //sdci[2]=x1
5949 //sdci[3]=y1
5950 //sdci[4]=x2
5951 //sdci[5]=y2
5952 //sdci[6]=x3
5953 //sdci[7]=y3
5954 //sdci[8]=x4
5955 //sdci[9]=y4
5956 //sdci[10]=width
5957 //sdci[11]=height
5958 //sdci[12]=cset
5959 //sdci[13]=flip
5960 //sdci[14]=tile/combo
5961 //sdci[15]=polytype
5962 //sdci[16] = other bitmap as texture
5963 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5964 Z_scripterrlog("bitmap quad pointer: %d\n", sdci[DRAWCMD_BMP_TARGET]);
5965 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5966 {
5967 Z_scripterrlog("bitmap->Quad() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5968 return;
5969 }
5970 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
5971
5972 if ( !refbmp ) return;
5973
5974 int32_t x1 = sdci[2]/10000;
5975 int32_t y1 = sdci[3]/10000;
5976 int32_t x2 = sdci[4]/10000;
5977 int32_t y2 = sdci[5]/10000;
5978 int32_t x3 = sdci[6]/10000;
5979 int32_t y3 = sdci[7]/10000;
5980 int32_t x4 = sdci[8]/10000;
5981 int32_t y4 = sdci[9]/10000;
5982 int32_t w = sdci[10]/10000;
5983 int32_t h = sdci[11]/10000;
5984 int32_t color = sdci[12]/10000;
5985 int32_t flip=(sdci[13]/10000)&3;
5986 int32_t tile = sdci[14]/10000;
5987 int32_t polytype = sdci[15]/10000;
5988 int32_t quad_render_source = sdci[16];
5989 //Z_scripterrlog("bitmap->Quad() render source is: %d\n", quad_render_source);
5990
5991 bool tex_is_bitmap = ( sdci[16] != 0 );
5992
5993 BITMAP *bmptexture=NULL;
5994 BITMAP *tex=NULL;
5995 polytype = vbound(polytype, 0, 14);
5996
5997 int32_t col[4];
5998 col[0]=col[1]=col[2]=col[3]=color;
5999 bool mustDestroyBmp = false;
6000
6001 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
6002
6003 if ( tex_is_bitmap )
6004 {
6005 bmptexture = FFCore.GetScriptBitmap(quad_render_source);
6006 if ( !bmptexture )
6007 {
6008 Z_scripterrlog("Bitmap pointer used as a texture in %s is uninitialised.\n Defaulting to using a tile as a texture.\n", "bitmap->Triangle3()");
6009 tex_is_bitmap = 0;
6010 }
6011 }
6012
6013 if ( tex_is_bitmap )
6014 {
6015
6016 if ( !isPowerOfTwo(bmptexture->h) ) Z_scripterrlog("HEIGHT of Bitmap ( pointer %d ) provided as a render source for bitmap->Quad is not a POWER OF TWO.\nTextels may render improperly!\n", quad_render_source);
6017 if ( !isPowerOfTwo(bmptexture->w) ) Z_scripterrlog("WIDTH of Bitmap ( pointer %d ) provided as a render source for bitmap->Quad is not a POWER OF TWO.\nTextels may render improperly!\n", quad_render_source);
6018 if ( !isPowerOfTwo(w) ) Z_scripterrlog("WIDTH ARG (%d) provided as a render source for bitmap->Quad is not a POWER OF TWO.\nTextels may render improperly!\n", w);
6019 if ( !isPowerOfTwo(h) ) Z_scripterrlog("HEIGHT ARG (%d) provided as a render source for bitmap->Quad is not a POWER OF TWO.\nTextels may render improperly!\n", h);
6020
6021 V3D_f V1 = { static_cast<float>(x1+xoffset), static_cast<float>(y1+yoffset), 0, 0, 0, col[0] };
6022 V3D_f V2 = { static_cast<float>(x2+xoffset), static_cast<float>(y2+yoffset), 0, 0, static_cast<float>(h), col[1] };
6023 V3D_f V3 = { static_cast<float>(x3+xoffset), static_cast<float>(y3+yoffset), 0, static_cast<float>(w), static_cast<float>(h), col[2] };
6024 V3D_f V4 = { static_cast<float>(x4+xoffset), static_cast<float>(y4+yoffset), 0, static_cast<float>(w), 0, col[3] };
6025
6026 quad3d_f(refbmp, polytype, bmptexture, &V1, &V2, &V3, &V4);
6027 }
6028 else
6029 {
6030 tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
6031 if(!tex)
6032 {
6033 //Z_scripterrlog("Bitmap->Quad() found an invalid texture bitmap.\n");
6034 mustDestroyBmp = true;
6035 tex = create_bitmap_ex(8, w*16, h*16);
6036 clear_bitmap(tex);
6037 }
6038
6039 if(tile > 0) // TILE
6040 {
6041 TileHelper::OverTile(tex, tile, 0, 0, w, h, color, flip);
6042 }
6043
6044 if ( tile < 0 ) // COMBO
6045 {
6046 auto& c = GET_DRAWING_COMBO(vbound(abs(tile), 0, 0xffff));
6047 const int32_t tiletodraw = combo_tile(c, x1, y1);
6048 flip = flip ^ c.flip;
6049
6050 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, color, flip);
6051 }
6052 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
6053 {
6054 Z_message("Quad() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
6055 return; //non power of two error
6056 }
6057 //Z_scripterrlog("bitmap->Quad() is trying to blit from a bitmap texture.\n");
6058 V3D_f V1 = { static_cast<float>(x1+xoffset), static_cast<float>(y1+yoffset), 0, 0, 0, col[0] };
6059 V3D_f V2 = { static_cast<float>(x2+xoffset), static_cast<float>(y2+yoffset), 0, 0, static_cast<float>(h), col[1] };
6060 V3D_f V3 = { static_cast<float>(x3+xoffset), static_cast<float>(y3+yoffset), 0, static_cast<float>(w), static_cast<float>(h), col[2] };
6061 V3D_f V4 = { static_cast<float>(x4+xoffset), static_cast<float>(y4+yoffset), 0, static_cast<float>(w), 0, col[3] };
6062
6063 quad3d_f(refbmp, polytype, tex, &V1, &V2, &V3, &V4);
6064
6065 }
6066
6067
6068
6069
6070 //todo: finish palette shading
6071 /*
6072 POLYTYPE_FLAT
6073 POLYTYPE_GCOL
6074 POLYTYPE_GRGB
6075 POLYTYPE_ATEX
6076 POLYTYPE_PTEX
6077 POLYTYPE_ATEX_MASK
6078 POLYTYPE_PTEX_MASK
6079 POLYTYPE_ATEX_LIT
6080 POLYTYPE_PTEX_LIT
6081 POLYTYPE_ATEX_MASK_LIT
6082 POLYTYPE_PTEX_MASK_LIT
6083 POLYTYPE_ATEX_TRANS
6084 POLYTYPE_PTEX_TRANS
6085 POLYTYPE_ATEX_MASK_TRANS
6086 POLYTYPE_PTEX_MASK_TRANS
6087 */
6088
6089 if(mustDestroyBmp)
6090 destroy_bitmap(tex);
6091
6092 }
6093
6094
6095 void bmp_do_getpixelr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
6096 {
6097 //sdci[1]=layer
6098 //sdci[2]=x1
6099 //sdci[3]=y1
6100
6101 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
6102 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
6103 {
6104 Z_scripterrlog("bitmap->GetPixel() wanted to read from an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
6105 return;
6106 }
6107 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
6108 if ( refbmp == NULL ) return;
6109
6110
6111 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
6112
6113 int32_t x1 = sdci[2]/10000;
6114 int32_t y1 = (sdci[3]/10000)+yoffset;
6115 int32_t col = getpixel(scb.get(sdci[DRAWCMD_BMP_TARGET]).u_bmp, x1, y1);
6116 Z_scripterrlog("bitmap->GetPixel col is %d\n",col);
6117 Z_scripterrlog("bitmap->GetPixel bitmap ptr is is %d\n",(sdci[DRAWCMD_BMP_TARGET]));
6118 FFCore.set_sarg1(col);
6119 }
6120
6121
6122
6123
6124 void bmp_do_drawtriangler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
6125 {
6126 //sdci[1]=layer
6127 //sdci[2]=x1
6128 //sdci[3]=y1
6129 //sdci[4]=x2
6130 //sdci[5]=y2
6131 //sdci[6]=x3
6132 //sdci[7]=y3
6133 //sdci[8]=width
6134 //sdci[9]=height
6135 //sdci[10]=cset
6136 //sdci[11]=flip
6137 //sdci[12]=tile/combo
6138 //sdci[13]=polytype
6139 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
6140 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
6141 {
6142 Z_scripterrlog("bitmap->Triangle() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
6143 return;
6144 }
6145 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
6146 if ( refbmp == NULL ) return;
6147
6148
6149 int32_t render_source = sdci[14];
6150 //Z_scripterrlog("bitmap->Triangle() render source is: %d\n", render_source);
6151
6152 bool tex_is_bitmap = ( sdci[14] != 0 );
6153
6154 BITMAP *bmptexture=NULL;
6155 if ( tex_is_bitmap )
6156 {
6157 bmptexture = FFCore.GetScriptBitmap(render_source);
6158 if ( !bmptexture )
6159 {
6160 Z_scripterrlog("Bitmap pointer used as a texture in %s is uninitialised.\n Defaulting to using a tile as a texture.\n", "bitmap->Triangle3()");
6161 tex_is_bitmap = 0;
6162 }
6163 }
6164
6165 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
6166
6167 int32_t x1 = sdci[2]/10000;
6168 int32_t y1 = sdci[3]/10000;
6169 int32_t x2 = sdci[4]/10000;
6170 int32_t y2 = sdci[5]/10000;
6171 int32_t x3 = sdci[6]/10000;
6172 int32_t y3 = sdci[7]/10000;
6173 int32_t w = sdci[8]/10000;
6174 int32_t h = sdci[9]/10000;
6175 int32_t color = sdci[10]/10000;
6176 int32_t flip=(sdci[11]/10000)&3;
6177 int32_t tile = sdci[12]/10000;
6178 int32_t polytype = sdci[13]/10000;
6179
6180 polytype = vbound(polytype, 0, 14);
6181 int32_t utex_w = w;
6182 int32_t utex_h = h;
6183
6184
6185 int32_t tex_width = w*16;
6186 int32_t tex_height = h*16;
6187
6188 bool mustDestroyBmp = false;
6189 BITMAP *tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
6190
6191 if(!tex)
6192 {
6193 mustDestroyBmp = true;
6194 tex = create_bitmap_ex(8, tex_width, tex_height);
6195 clear_bitmap(tex);
6196 }
6197
6198 int32_t col[3];
6199 /*
6200 if( color < 0 )
6201 {
6202 col[0]=draw_container.color_buffer[0];
6203 col[1]=draw_container.color_buffer[1];
6204 col[2]=draw_container.color_buffer[2];
6205 }
6206 else */
6207 {
6208 col[0]=col[1]=col[2]=color;
6209 }
6210
6211 if(tile > 0) // TILE
6212 {
6213 TileHelper::OverTile(tex, tile, 0, 0, w, h, color, flip);
6214 }
6215 else // COMBO
6216 {
6217 auto& c = GET_DRAWING_COMBO(vbound(abs(tile), 0, 0xffff));
6218 const int32_t tiletodraw = combo_tile(c, x1, y1);
6219 flip = flip ^ c.flip;
6220
6221 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, color, flip);
6222 }
6223 if ( !tex_is_bitmap )
6224 {
6225 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
6226 {
6227 Z_message("bitmap->Triangle() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
6228 return; //non power of two error
6229 }
6230 V3D_f V1 = { static_cast<float>(x1+xoffset), static_cast<float>(y1+yoffset), 0, 0, 0, col[0] };
6231 V3D_f V2 = { static_cast<float>(x2+xoffset), static_cast<float>(y2+yoffset), 0, 0, static_cast<float>(tex_height), col[1] };
6232 V3D_f V3 = { static_cast<float>(x3+xoffset), static_cast<float>(y3+yoffset), 0, static_cast<float>(tex_width), static_cast<float>(tex_height), col[2] };
6233
6234
6235 triangle3d_f(refbmp, polytype, tex, &V1, &V2, &V3);
6236
6237 }
6238
6239 else
6240 {
6241 if ( !isPowerOfTwo(bmptexture->h) ) Z_scripterrlog("HEIGHT of Bitmap ( pointer %d ) provided as a render source for bitmap->Triangle is not a POWER OF TWO.\nTextels may render improperly!\n", render_source);
6242 if ( !isPowerOfTwo(bmptexture->w) ) Z_scripterrlog("WIDTH of Bitmap ( pointer %d ) provided as a render source for bitmap->Triangle is not a POWER OF TWO.\nTextels may render improperly!\n", render_source);
6243 if ( !isPowerOfTwo(utex_h) ) Z_scripterrlog("WIDTH ARG (%d) provided as a render source for bitmap->Triangle is not a POWER OF TWO.\nTextels may render improperly!\n", utex_w);
6244 if ( !isPowerOfTwo(utex_w) ) Z_scripterrlog("HEIGHT ARG (%d) provided as a render source for bitmap->Triangle is not a POWER OF TWO.\nTextels may render improperly!\n", utex_h);
6245
6246 V3D_f V1 = { static_cast<float>(x1+xoffset), static_cast<float>(y1+yoffset), 0, 0, 0, col[0] };
6247 V3D_f V2 = { static_cast<float>(x2+xoffset), static_cast<float>(y2+yoffset), 0, 0, static_cast<float>(utex_h), col[1] };
6248 V3D_f V3 = { static_cast<float>(x3+xoffset), static_cast<float>(y3+yoffset), 0, static_cast<float>(utex_w), static_cast<float>(utex_h), col[2] };
6249
6250
6251 triangle3d_f(refbmp, polytype, bmptexture, &V1, &V2, &V3);
6252
6253 }
6254
6255 if(mustDestroyBmp)
6256 destroy_bitmap(tex);
6257 }
6258
6259
6260 void bmp_do_mode7r(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
6261 {
6262 /*
6263 int32_t layer, int32_t rt, int32_t srcX, int32_t srcY, int32_t srcW, int32_t srcH, int32_t destW, int32_t destH, int32_t angle, int32_t cx, int32_t cy, int32_t space_z, int32_t horizon,
6264 int32_t scale_x, int32_t scale_y){
6265
6266 //sdci[1]=layer
6267 //sdci[2]=bitmap target
6268 //
6269 // -2 is the current Render Target
6270 // -1, this is the screen (framebuf).
6271 // 0: Render target 0
6272 // 1: Render target 1
6273 // 2: Render target 2
6274 // 3: Render target 3
6275 // 4: Render target 4
6276 // 5: Render target 5
6277 // 6: Render target 6
6278 // Otherwise: The pointer to a bitmap.
6279
6280 //sdci[3]=sourcex
6281 //sdci[4]=sourcey
6282 //sdci[5]=sourcew
6283 //sdci[6]=sourceh
6284
6285 //sdci[7]=destw
6286 //sdci[8]=desth
6287 //sdci[9]=angle
6288 //scdi[10] = pivot cx
6289 //sdci[11] = pivot cy
6290 //sdci[12] = space Z
6291 //sdci[13] = horizon
6292 //scdi[14] = scale X
6293 //scdi[15] = scale Y
6294 //sdci[16] = masked?
6295 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
6296
6297
6298
6299 // ZScript-side constant values:
6300 const int32_t BITDX_NORMAL = 0;
6301 const int32_t BITDX_TRANS = 1; //Translucent
6302 const int32_t BITDX_PIVOT = 2; //THe sprite will rotate at a specific point, instead of its center.
6303 const int32_t BITDX_HFLIP = 4; //Horizontal Flip
6304 const int32_t BITDX_VFLIP = 8; //Vertical Flip.
6305 //Note: Some modes cannot be combined. if a combination is not supported, an error
6306 // detailing this will be shown in allegro.log.
6307
6308 //scdi[15] = litcolour
6309 //The allegro docs are wrong. The params are: rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
6310 //not rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
6311
6312 //sdci[16]=mask
6313
6314 */
6315
6316
6317 int32_t bitmapIndex = sdci[2];
6318 int32_t usr_bitmap_index = sdci[2];
6319 //Z_scripterrlog("bitmap index is: %d\n",bitmapIndex);
6320 //Z_scripterrlog("DrawPlane() bitmapIndex is: %d\n", bitmapIndex);
6321
6322 if ( bitmapIndex >= 10000 )
6323 {
6324 bitmapIndex = bitmapIndex / 10000; //reduce if ZScript sent a raw value, such as bitmap = <int32_t> 8;
6325 }
6326 else if ( usr_bitmap_index > 0 )
6327 {
6328 bitmapIndex = usr_bitmap_index;
6329 // Z_scripterrlog("Mode7 is using a user bitmap target, pointer: %d\n", usr_bitmap_index);
6330 yoffset = 0;
6331 }
6332
6333 //rendering mode 7 args
6334 double srcX = sdci[3]/10000.0;
6335 double srcY = sdci[4]/10000.0;
6336 double destX = sdci[5]/10000.0;
6337 double destY = sdci[6]/10000.0;
6338
6339 double destW = sdci[7]/10000.0;
6340 double destH = sdci[8]/10000.0;
6341 double space_z = sdci[9]/10000.0;
6342 double horizon = sdci[10]/10000.0;
6343 double scale_x = sdci[11]/10000.0;
6344 double scale_y = sdci[12]/10000.0;
6345 byte masked = ( sdci[13] ) ? 1 : 0;
6346
6347
6348 int32_t ref = 0;
6349
6350 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
6351 //Do we need to also check the render target and do the same thing if the
6352 //dest == -2 and the render target is not RT_SCREEN?
6353
6354 ref = sdci[DRAWCMD_BMP_TARGET];
6355
6356
6357 if ( ref <= 0 )
6358 {
6359 Z_scripterrlog("bitmap->DrawPlane() wanted to use to an invalid source bitmap id: %d. Aborting.\n", ref);
6360 return;
6361 }
6362 BITMAP *sourceBitmap = FFCore.GetScriptBitmap(ref); //This can be the screen, as -1.
6363
6364 if(!sourceBitmap)
6365 {
6366 Z_message("Warning: %d->DrawPlane() source bitmap contains invalid data or is not initialized.\n", ref);
6367 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
6368 return;
6369 }
6370
6371 BITMAP *destBMP=NULL;
6372 switch(bitmapIndex)
6373 {
6374 case -2:
6375 {
6376 int32_t curr_rt = zscriptDrawingRenderTarget->GetCurrentRenderTarget();
6377 if ( curr_rt >= 0 && curr_rt < 7 )
6378 destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex); //Drawing to the current RenderTarget.
6379 else destBMP = bmp; //screen
6380 break;
6381 }
6382 case -1:
6383 destBMP = bmp; //this is framebuf, by default
6384 break;
6385
6386 //1 through 6 are the old system bitmaps (Render Targets)
6387 case 0:
6388 case 1:
6389 case 2:
6390 case 3:
6391 case 4:
6392 case 5:
6393 case 6:
6394 {
6395 //This gets a render target.
6396 destBMP = zscriptDrawingRenderTarget->GetTargetBitmap(bitmapIndex);
6397 break;
6398 }
6399 //Otherwise, we are using a user-created bitmap, so, get that pointer insted.
6400 default:
6401 {
6402 auto& usr_bitmap = scb.get(usr_bitmap_index);
6403 destBMP = usr_bitmap.u_bmp;
6404 if ( !usr_bitmap.u_bmp )
6405 {
6406 Z_scripterrlog("Target for bitmap->DrawPlane is uninitialised. Aborting.\n");
6407 break;
6408 }
6409 }
6410 }
6411
6412 if (!destBMP)
6413 {
6414 Z_message("Warning: DrawPlane(%d) destination bitmap contains invalid data or is not initialized.\n", bitmapIndex);
6415 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
6416 return;
6417 }
6418
6419 //dx = dx + xoffset; //don't do this here!
6420 //dy = dy + yoffset; //Nor this. It auto-offsets the bitmap by +56. Hmm. The fix that gleeok made isn't being applied to these functions. -Z ( 17th April, 2019 )
6421 //All of these are a factor of 10000 as fix.
6422 int32_t screen_x = 0; int32_t screen_y = 0;
6423
6424 double distance = 0; double horizontal_scale = 0;
6425
6426 int32_t screen_y_horizon = 0;
6427
6428 double line_dx = 0; double line_dy = 0;
6429
6430 int32_t space_x = 0; int32_t space_y = 0;
6431
6432 for(screen_y = 0; screen_y < destH; screen_y++) //fix, offset by .0000
6433 {
6434 //Calculate the distance of each line from the camera point
6435 screen_y_horizon = screen_y + horizon;
6436
6437 distance = ((space_z * scale_y) / ((screen_y_horizon != 0) ? screen_y_horizon : 1));
6438
6439 //Get the scale of each line based on the distance
6440
6441 horizontal_scale = (distance / (( scale_x != 0 ) ? scale_x : 1));
6442
6443 //There was some math here before I stripped out the rotation step
6444 line_dx = horizontal_scale;
6445 line_dy = 0;
6446
6447 //space_x,space_y - where to grab each scanline from on the space bitmap
6448 space_x = srcX - destW/2.0 * line_dx;
6449 space_y = srcY - distance + destH/2.0 * line_dy;
6450
6451 //Keep blits within the bounds of both bitmaps to avoid crashes
6452 int32_t y1 = srcY+space_y;
6453 int32_t y2 = destY+screen_y;
6454 if(y1 >=0 && y1 <= (sourceBitmap->h-1) && y2 >=0 && y2 <= (destBMP->h-1) )
6455 {
6456 if ( masked ) masked_stretch_blit(sourceBitmap, destBMP, (int32_t)(srcX+space_x), (int32_t)(srcY+space_y),
6457 (int32_t)(line_dx*destW), 1, (int32_t)(screen_x), (int32_t)(screen_y)+yoffset, (int32_t)(destW), 1);
6458 else stretch_blit(sourceBitmap, destBMP, (int32_t)(srcX+space_x), (int32_t)(srcY+space_y),
6459 (int32_t)(line_dx*destW), 1, (int32_t)(screen_x), (int32_t)(screen_y)+yoffset, (int32_t)(destW), 1);
6460 }
6461 }
6462 }
6463
6464
6465 //Draw]()
6466 265509 void bmp_do_drawbitmapexr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
6467 {
6468 /*
6469 //sdci[1]=layer
6470 //sdci[2]=bitmap target
6471 //
6472 // -2 is the current Render Target
6473 // -1, this is the screen (framebuf).
6474 // 0: Render target 0
6475 // 1: Render target 1
6476 // 2: Render target 2
6477 // 3: Render target 3
6478 // 4: Render target 4
6479 // 5: Render target 5
6480 // 6: Render target 6
6481 // Otherwise: The pointer to a bitmap.
6482
6483 //sdci[3]=sourcex
6484 //sdci[4]=sourcey
6485 //sdci[5]=sourcew
6486 //sdci[6]=sourceh
6487 //sdci[7]=destx
6488 //sdci[8]=desty
6489 //sdci[9]=destw
6490 //sdci[10]=desth
6491 //sdci[11]=rotation/angle
6492 //scdi[12] = pivot cx
6493 //sdci[13] = pivot cy
6494 //scdi[14] = effect flags
6495 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
6496
6497 // ZScript-side constant values:
6498 const int32_t BITDX_NORMAL = 0;
6499 const int32_t BITDX_TRANS = 1; //Translucent
6500 const int32_t BITDX_PIVOT = 2; //THe sprite will rotate at a specific point, instead of its center.
6501 const int32_t BITDX_HFLIP = 4; //Horizontal Flip
6502 const int32_t BITDX_VFLIP = 8; //Vertical Flip.
6503 //Note: Some modes cannot be combined. if a combination is not supported, an error
6504 // detailing this will be shown in allegro.log.
6505
6506 //scdi[15] = litcolour
6507 //The allegro docs are wrong. The params are: rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
6508 //not rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
6509
6510 //sdci[16]=mask
6511
6512 */
6513
6514 265509 int32_t usr_bitmap_index = sdci[2];
6515 531018 auto [bitmapIndex, is_user_bitmap] = resolveScriptingBitmapId(usr_bitmap_index);
6516
6517
6518 265509 int32_t sx = sdci[3]/10000;
6519 265509 int32_t sy = sdci[4]/10000;
6520 265509 int32_t sw = sdci[5]/10000;
6521 265509 int32_t sh = sdci[6]/10000;
6522 265509 int32_t dx = sdci[7]/10000;
6523 265509 int32_t dy = sdci[8]/10000;
6524 265509 int32_t dw = sdci[9]/10000;
6525 265509 int32_t dh = sdci[10]/10000;
6526 265509 float rot = sdci[11]/10000;
6527 265509 int32_t cx = sdci[12]/10000;
6528 265509 int32_t cy = sdci[13]/10000;
6529 265509 int32_t mode = sdci[14]/10000;
6530 265509 int32_t litcolour = sdci[15]/10000;
6531 265509 bool masked = (sdci[16] != 0);
6532
6533 265509 int32_t ref = 0;
6534
6535
2/2
✓ Branch 0 taken 265149 times.
✓ Branch 1 taken 360 times.
265509 if (get_qr(qr_BROKEN_SCRIPTS_BITMAP_DRAW_ORIGIN))
6536 {
6537
2/2
✓ Branch 0 taken 92926 times.
✓ Branch 1 taken 172223 times.
265149 if (is_user_bitmap)
6538 172223 yoffset = 0;
6539
6540 265149 dx += xoffset;
6541 265149 dy += yoffset;
6542 265149 }
6543 else
6544 {
6545 360 dx += secondary_draw_origin_xoff;
6546 360 dy += secondary_draw_origin_yoff;
6547
6548 360 sx += xoffset;
6549 360 sy += yoffset;
6550 }
6551
6552 265509 ref = sdci[DRAWCMD_BMP_TARGET];
6553
6554
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 265509 times.
265509 if ( ref <= 0 )
6555 {
6556 Z_scripterrlog("bitmap->blit() wanted to use to an invalid source bitmap id: %d. Aborting.\n", ref);
6557 return;
6558 }
6559 265509 BITMAP *sourceBitmap = FFCore.GetScriptBitmap(ref); //This can be the screen, as -1.
6560
6561
1/2
✓ Branch 0 taken 265509 times.
✗ Branch 1 not taken.
265509 if(!sourceBitmap)
6562 {
6563
6564 Z_message("Warning: blit(%d) source bitmap contains invalid data or is not initialized.\n", ref);
6565 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
6566 return;
6567 }
6568
6569 265509 BITMAP *destBMP=NULL;
6570
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 172223 times.
✓ Branch 2 taken 786 times.
✓ Branch 3 taken 92500 times.
265509 switch(bitmapIndex)
6571 {
6572 case -2:
6573 {
6574 786 int32_t curr_rt = zscriptDrawingRenderTarget->GetCurrentRenderTarget();
6575
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 786 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
786 if ( curr_rt >= 0 && curr_rt < 7 )
6576 destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex); //Drawing to the current RenderTarget.
6577 786 else destBMP = bmp; //screen
6578 786 break;
6579 }
6580 case -1:
6581 92500 destBMP = bmp; //this is framebuf, by default
6582 92500 break;
6583 //zscriptDrawingRenderTarget->SetCurrentRenderTarget(bitmapIndex);
6584 //destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex);
6585 //destBMP = framebuf; //Drawing to the screen.
6586 //break;
6587
6588 //1 through 6 are the old system bitmaps (Render Targets)
6589 case 0:
6590 case 1:
6591 case 2:
6592 case 3:
6593 case 4:
6594 case 5:
6595 case 6:
6596 {
6597 //This gets a render target.
6598 destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex); break;
6599
6600 //destBMP = zscriptDrawingRenderTarget->GetTargetBitmap(bitmapIndex);
6601 //sdci[18] = bitmapIndex;
6602 break;
6603 }
6604 //Otherwise, we are using a user-created bitmap, so, get that pointer insted.
6605 default:
6606 {
6607 172223 auto& usr_bitmap = scb.get(usr_bitmap_index);
6608 172223 destBMP = usr_bitmap.u_bmp;
6609 //sdci[18] = usr_bitmap_index;
6610
1/2
✓ Branch 0 taken 172223 times.
✗ Branch 1 not taken.
172223 if ( !usr_bitmap.u_bmp )
6611 {
6612 Z_scripterrlog("Target for bitmap->Blit is uninitialised. Aborting.\n");
6613 break;
6614 }
6615 }
6616 172223 }
6617
6618
1/2
✓ Branch 0 taken 265509 times.
✗ Branch 1 not taken.
265509 if (!destBMP)
6619 {
6620 Z_message("Warning: blit(%d) destination bitmap contains invalid data or is not initialized.\n", bitmapIndex);
6621 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
6622 return;
6623 }
6624
6625
2/2
✓ Branch 0 taken 1027 times.
✓ Branch 1 taken 264482 times.
265509 bool stretched = (sw != dw || sh != dh);
6626 265509 BITMAP* subBmp = 0;
6627
6628
4/4
✓ Branch 0 taken 263930 times.
✓ Branch 1 taken 1579 times.
✓ Branch 2 taken 24983 times.
✓ Branch 3 taken 238947 times.
265509 if(rot != 0 || mode != 0)
6629 {
6630 26562 subBmp = create_bitmap_ex(8,sourceBitmap->w, sourceBitmap->h);//script_drawing_commands.AquireSubBitmap(dw, dh);
6631 26562 clear_bitmap(subBmp);
6632
6633
1/2
✓ Branch 0 taken 26562 times.
✗ Branch 1 not taken.
26562 if(!subBmp)
6634 {
6635
6636 Z_scripterrlog("bitmap->Blit failed to create a sub-bitmap to use for %s. Aborting.\n", "rotation");
6637 return;
6638 }
6639 26562 }
6640 265509 BITMAP* sbmp = sourceBitmap;
6641
2/4
✓ Branch 0 taken 265509 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 265509 times.
265509 if (sx + sw > sbmp->w || sy + sh > sbmp->h)
6642 {
6643 sbmp = create_bitmap_ex(8, sw, sh);
6644 clear_bitmap(sbmp);
6645 blit(sourceBitmap, sbmp, sx, sy, 0, 0, std::min(sourceBitmap->w-sx, sw), std::min(sourceBitmap->h-sy, sh));
6646 sx = 0;
6647 sy = 0;
6648 }
6649 //dx = dx + xoffset; //don't do this here!
6650 //dy = dy + yoffset; //Nor this. It auto-offsets the bitmap by +56. Hmm. The fix that gleeok made isn't being applied to these functions. -Z ( 17th April, 2019 )
6651
6652
2/2
✓ Branch 0 taken 1602 times.
✓ Branch 1 taken 263907 times.
265509 if(stretched)
6653 {
6654
2/2
✓ Branch 0 taken 1475 times.
✓ Branch 1 taken 127 times.
1602 if(masked)
6655 { //stretched and masked
6656
2/2
✓ Branch 0 taken 574 times.
✓ Branch 1 taken 901 times.
1475 if ( rot == 0 )
6657 { //if not rotated
6658
2/22
✗ Branch 0 not taken.
✓ Branch 1 taken 900 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 1 times.
901 switch(mode)
6659 {
6660 case 1:
6661 //transparent
6662 900 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6663 900 draw_trans_sprite(destBMP, subBmp, dx, dy);
6664 900 break;
6665
6666
6667 case 2:
6668 //pivot?
6669 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6670 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
6671 //Pivoting requires two more args
6672 break;
6673
6674 case 3:
6675 //pivot + trans
6676 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6677 pivot_sprite_trans(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
6678 break;
6679
6680 case 4:
6681 //flip v
6682 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6683 draw_sprite_v_flip(destBMP, subBmp, dx, dy);
6684 break;
6685
6686 case 5:
6687 //trans + v flip
6688 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6689 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
6690 break;
6691
6692 case 6:
6693 //pivot + v flip
6694 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6695 pivot_sprite_v_flip(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
6696 break;
6697
6698 case 8:
6699 //vlip h
6700 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6701 draw_sprite_h_flip(destBMP, subBmp, dx, dy);
6702 break;
6703
6704 case 9:
6705 //trans + h flip
6706 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6707 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
6708 break;
6709
6710 case 10:
6711 //flip H and pivot
6712 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
6713 //return error cannot pivot and h flip
6714 break;
6715
6716 case 12:
6717 //vh flip
6718 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6719 draw_sprite_vh_flip(destBMP, subBmp, dx, dy);
6720 break;
6721
6722 case 13:
6723 //trans + vh flip
6724 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6725 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
6726 break;
6727
6728 case 14:
6729 //pivot and vh flip
6730 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
6731 //return error cannot both pivot and vh flip
6732 break;
6733
6734 case 16:
6735 //lit
6736 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6737 draw_lit_sprite(destBMP, subBmp, dx, dy, litcolour);
6738 break;
6739
6740 case 18:
6741 //pivot, lit
6742 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6743 pivot_sprite_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
6744 break;
6745
6746 case 20:
6747 //lit + v flip
6748 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6749 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
6750 break;
6751
6752 case 22:
6753 //Pivot, vflip, lit
6754 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6755 pivot_sprite_v_flip_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
6756 break;
6757
6758 case 24:
6759 //lit + h flip
6760 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6761 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
6762 break;
6763
6764 case 26:
6765 //pivot + lit + hflip
6766 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
6767 //return error cannot pivot, lit, and flip
6768 break;
6769
6770 case 28:
6771 //lit + vh flip
6772 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6773 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
6774 break;
6775
6776 case 32: //gouraud
6777 //Probably not wort supporting.
6778 //masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6779 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
6780 break;
6781
6782 case 0:
6783 //no effect
6784 1 masked_stretch_blit(sbmp, destBMP, sx, sy, sw, sh, dx, dy, dw, dh);
6785 1 break;
6786
6787
6788 default:
6789
6790 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
6791
6792
6793 }
6794 901 } //end if not rotated
6795
6796
2/2
✓ Branch 0 taken 901 times.
✓ Branch 1 taken 574 times.
1475 if ( rot != 0 ) //if rotated
6797 {
6798
1/22
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 20 taken 574 times.
✗ Branch 21 not taken.
574 switch(mode)
6799 {
6800 case 1:
6801 //transparent
6802 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6803 rotate_sprite_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
6804
6805 break;
6806
6807 case 2:
6808 //pivot?
6809 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6810 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
6811 //Pivoting requires two more args
6812 break;
6813
6814 case 3:
6815 //pivot + trans
6816 //return an error, cannot both rotate and pivot
6817 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
6818 break;
6819
6820 case 4:
6821 //flip v
6822 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6823 rotate_sprite_v_flip(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
6824 break;
6825
6826 case 5:
6827 //trans + v flip
6828 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6829 rotate_sprite_v_flip_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
6830 break;
6831
6832 case 6:
6833 //pivot + v flip
6834 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
6835 //return an error, cannot both rotate and pivot
6836 break;
6837
6838 case 8:
6839 //flip h
6840 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
6841 //return an error, cannot both rotate and flip H
6842 break;
6843
6844 case 9:
6845 //trans + h flip
6846 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
6847 //return an error, cannot rotate and flip a trans sprite
6848 break;
6849
6850 case 10:
6851 //flip H and pivot
6852 //return error cannot pivot and h flip
6853 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
6854 break;
6855
6856 case 12:
6857 //vh flip
6858 //return an error, cannot rotate and VH flip a trans sprite
6859 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
6860 break;
6861
6862 case 13:
6863 //trans + vh flip
6864 //return an error, cannot rotate and VH flip a trans sprite
6865 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
6866 break;
6867
6868 case 14:
6869 //pivot and vh flip
6870 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
6871 //return error cannot both pivot and vh flip
6872 break;
6873
6874 case 16:
6875 //lit
6876 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6877 rotate_sprite_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
6878 break;
6879
6880 case 18:
6881 //pivot, lit
6882 //return an error, cannot both rotate and pivot
6883 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
6884 break;
6885
6886 case 20:
6887 //lit + vflip
6888 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6889 rotate_sprite_v_flip_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
6890 break;
6891
6892 case 22:
6893 //Pivot, vflip, lit
6894 //return an error, cannot both rotate and pivot
6895 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
6896 break;
6897
6898 case 24:
6899 //lit + h flip
6900 //return an error, cannot both rotate and H flip
6901 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
6902 break;
6903
6904 case 26:
6905 //pivot + lit + hflip
6906 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
6907 //return error cannot pivot, lit, and flip
6908 break;
6909
6910 case 28:
6911 //lit + vh flip
6912 //return an error, cannot both rotate and VH flip
6913 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
6914 break;
6915
6916 case 32: //gouraud
6917 //Probably not wort supporting.
6918 //masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6919 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
6920 break;
6921
6922 case 0:
6923 //no effect.
6924 574 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6925 574 rotate_sprite(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
6926 574 break;
6927
6928 default:
6929
6930 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
6931
6932 }
6933 574 }
6934 1475 } //end if stretched and masked
6935
6936 else //stretched, not masked
6937 {
6938
6939
6940
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 127 times.
127 if ( rot == 0 ) //if not rotated
6941 {
6942
1/22
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 127 times.
127 switch(mode)
6943 {
6944 case 1:
6945 //transparent
6946 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6947 draw_trans_sprite(destBMP, subBmp, dx, dy);
6948 break;
6949
6950
6951 case 2:
6952 //pivot?
6953 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6954 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
6955 //Pivoting requires two more args
6956 break;
6957
6958 case 3:
6959 //pivot + trans
6960 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6961 pivot_sprite_trans(destBMP, subBmp, dx,dy, cx, cy, degrees_to_fixed(rot));
6962 break;
6963
6964 case 4:
6965 //flip v
6966 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6967 draw_sprite_v_flip(destBMP, subBmp, dx, dy);
6968 break;
6969
6970 case 5:
6971 //trans + v flip
6972 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6973 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
6974 break;
6975
6976 case 6:
6977 //pivot + v flip
6978 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6979 pivot_sprite_v_flip(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
6980 break;
6981
6982 case 8:
6983 //vlip h
6984 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6985 draw_sprite_h_flip(destBMP, subBmp, dx, dy);
6986 break;
6987
6988 case 9:
6989 //trans + h flip
6990 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6991 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
6992 break;
6993
6994 case 10:
6995 //flip H and pivot
6996 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
6997 //return error cannot pivot and h flip
6998 break;
6999
7000 case 12:
7001 //vh flip
7002 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7003 draw_sprite_vh_flip(destBMP, subBmp, dx, dy);
7004 break;
7005
7006 case 13:
7007 //trans + vh flip
7008 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7009 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
7010 break;
7011
7012 case 14:
7013 //pivot and vh flip
7014 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
7015 //return error cannot both pivot and vh flip
7016 break;
7017
7018 case 16:
7019 //lit
7020 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7021 draw_lit_sprite(destBMP, subBmp, dx, dy, litcolour);
7022 break;
7023
7024 case 18:
7025 //pivot, lit
7026 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7027 pivot_sprite_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
7028 break;
7029
7030 case 20:
7031 //lit + v flip
7032 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7033 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
7034 break;
7035
7036 case 22:
7037 //Pivot, vflip, lit
7038 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7039 pivot_sprite_v_flip_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
7040 break;
7041
7042 case 24:
7043 //lit + h flip
7044 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7045 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
7046 break;
7047
7048 case 26:
7049 //pivot + lit + hflip
7050 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
7051 //return error cannot pivot, lit, and flip
7052 break;
7053
7054 case 28:
7055 //lit + vh flip
7056 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7057 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
7058 break;
7059
7060 case 32: //gouraud
7061 //Probably not wort supporting.
7062 //stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7063 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7064 break;
7065
7066 case 0:
7067 //no effect
7068 127 stretch_blit(sbmp, destBMP, sx, sy, sw, sh, dx, dy, dw, dh);
7069 127 break;
7070
7071
7072 default:
7073
7074 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7075
7076
7077 }
7078 127 } //end if not rotated
7079
7080
1/2
✓ Branch 0 taken 127 times.
✗ Branch 1 not taken.
127 if ( rot != 0 ) //if rotated
7081 {
7082 switch(mode)
7083 {
7084 case 1:
7085 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
7086 rotate_sprite_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7087
7088 break;
7089
7090 case 2:
7091 //pivot?
7092 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7093 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7094 //Pivoting requires two more args
7095 break;
7096
7097 case 3:
7098 //pivot + trans
7099 //return an error, cannot both rotate and pivot
7100 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7101 break;
7102
7103 case 4:
7104 //flip v
7105 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7106 rotate_sprite_v_flip(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7107 break;
7108
7109 case 5:
7110 //trans + v flip
7111 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7112 rotate_sprite_v_flip_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7113 break;
7114
7115 case 6:
7116 //pivot + v flip
7117 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7118 //return an error, cannot both rotate and pivot
7119 break;
7120
7121 case 8:
7122 //flip h
7123 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
7124 //return an error, cannot both rotate and flip H
7125 break;
7126
7127 case 9:
7128 //trans + h flip
7129 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
7130 //return an error, cannot rotate and flip a trans sprite
7131 break;
7132
7133 case 10:
7134 //flip H and pivot
7135 //return error cannot pivot and h flip
7136 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
7137 break;
7138
7139 case 12:
7140 //vh flip
7141 //return an error, cannot rotate and VH flip a trans sprite
7142 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7143 break;
7144
7145 case 13:
7146 //trans + vh flip
7147 //return an error, cannot rotate and VH flip a trans sprite
7148 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7149 break;
7150
7151 case 14:
7152 //pivot and vh flip
7153 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7154 //return error cannot both pivot and vh flip
7155 break;
7156
7157 case 16:
7158 //lit
7159 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
7160 rotate_sprite_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7161 break;
7162
7163 case 18:
7164 //pivot, lit
7165 //return an error, cannot both rotate and pivot
7166 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7167 break;
7168
7169 case 20:
7170 //lit + vflip
7171 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
7172 rotate_sprite_v_flip_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7173 break;
7174
7175 case 22:
7176 //Pivot, vflip, lit
7177 //return an error, cannot both rotate and pivot
7178 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7179 break;
7180
7181 case 24:
7182 //lit + h flip
7183 //return an error, cannot both rotate and H flip
7184 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
7185 break;
7186
7187 case 26:
7188 //pivot + lit + hflip
7189 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
7190 //return error cannot pivot, lit, and flip
7191 break;
7192
7193 case 28:
7194 //lit + vh flip
7195 //return an error, cannot both rotate and VH flip
7196 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
7197 break;
7198
7199 case 32: //gouraud
7200 //Probably not wort supporting.
7201 //stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7202 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7203 break;
7204
7205 case 0:
7206 //no effect.
7207 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7208 rotate_sprite(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7209 break;
7210
7211 default:
7212
7213 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7214
7215 }
7216 }
7217
7218 } //end if stretched, but not masked
7219 1602 }
7220 else //not stretched
7221 {
7222
7223
2/2
✓ Branch 0 taken 252924 times.
✓ Branch 1 taken 10983 times.
263907 if(masked) //if masked, but not stretched
7224 {
7225
7226
2/2
✓ Branch 0 taken 1005 times.
✓ Branch 1 taken 251919 times.
252924 if ( rot == 0 ) //if not rotated
7227 {
7228
2/22
✗ Branch 0 not taken.
✓ Branch 1 taken 18689 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 233230 times.
251919 switch(mode)
7229 {
7230 case 1:
7231 //transparent
7232 18689 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7233 18689 draw_trans_sprite(destBMP, subBmp, dx, dy);
7234 18689 break;
7235
7236
7237 case 2:
7238 //pivot?
7239 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7240 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7241 //Pivoting requires two more args
7242 break;
7243
7244 case 3:
7245 //pivot + trans
7246 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7247 pivot_sprite_trans(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7248 break;
7249
7250 case 4:
7251 //flip v
7252 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7253 draw_sprite_v_flip(destBMP, subBmp, dx, dy);
7254 break;
7255
7256 case 5:
7257 //trans + v flip
7258 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7259 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
7260 break;
7261
7262 case 6:
7263 //pivot + v flip
7264 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7265 pivot_sprite_v_flip(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7266 break;
7267
7268 case 8:
7269 //vlip h
7270 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7271 draw_sprite_h_flip(destBMP, subBmp, dx, dy);
7272 break;
7273
7274 case 9:
7275 //trans + h flip
7276 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7277 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
7278 break;
7279
7280 case 10:
7281 //flip H and pivot
7282 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
7283 //return error cannot pivot and h flip
7284 break;
7285
7286 case 12:
7287 //vh flip
7288 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7289 draw_sprite_vh_flip(destBMP, subBmp, dx, dy);
7290 break;
7291
7292 case 13:
7293 //trans + vh flip
7294 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7295 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
7296 break;
7297
7298 case 14:
7299 //pivot and vh flip
7300 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
7301 //return error cannot both pivot and vh flip
7302 break;
7303
7304 case 16:
7305 //lit
7306 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7307 draw_lit_sprite(destBMP, subBmp, dx, dy, litcolour);
7308 break;
7309
7310 case 18:
7311 //pivot, lit
7312 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7313 pivot_sprite_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
7314 break;
7315
7316 case 20:
7317 //lit + v flip
7318 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7319 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
7320 break;
7321
7322 case 22:
7323 //Pivot, vflip, lit
7324 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7325 pivot_sprite_v_flip_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
7326 break;
7327
7328 case 24:
7329 //lit + h flip
7330 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7331 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
7332 break;
7333
7334 case 26:
7335 //pivot + lit + hflip
7336 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
7337 //return error cannot pivot, lit, and flip
7338 break;
7339
7340 case 28:
7341 //lit + vh flip
7342 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7343 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
7344 break;
7345
7346 case 32: //gouraud
7347 //Probably not wort supporting.
7348 //stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7349 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7350 break;
7351
7352 case 0:
7353 //no effect
7354 233230 masked_blit(sbmp, destBMP, sx, sy, dx, dy, dw, dh);
7355 233230 break;
7356
7357
7358 default:
7359
7360 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7361
7362
7363 }
7364 251919 } //end if not rotated
7365
7366
2/2
✓ Branch 0 taken 251919 times.
✓ Branch 1 taken 1005 times.
252924 if ( rot != 0 ) //if rotated
7367 {
7368
1/22
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 20 taken 1005 times.
✗ Branch 21 not taken.
1005 switch(mode)
7369 {
7370 case 1:
7371 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh); //transparent
7372 rotate_sprite_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7373
7374 break;
7375
7376 case 2:
7377 //pivot?
7378 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7379 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7380 //Pivoting requires two more args
7381 break;
7382
7383 case 3:
7384 //pivot + trans
7385 //return an error, cannot both rotate and pivot
7386 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7387 break;
7388
7389 case 4:
7390 //flip v
7391 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7392 rotate_sprite_v_flip(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7393 break;
7394
7395 case 5:
7396 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh); //trans + v flip
7397 rotate_sprite_v_flip_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7398 break;
7399
7400 case 6:
7401 //pivot + v flip
7402 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7403 //return an error, cannot both rotate and pivot
7404 break;
7405
7406 case 8:
7407 //flip h
7408 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
7409 //return an error, cannot both rotate and flip H
7410 break;
7411
7412 case 9:
7413 //trans + h flip
7414 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
7415 //return an error, cannot rotate and flip a trans sprite
7416 break;
7417
7418 case 10:
7419 //flip H and pivot
7420 //return error cannot pivot and h flip
7421 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
7422 break;
7423
7424 case 12:
7425 //vh flip
7426 //return an error, cannot rotate and VH flip a trans sprite
7427 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7428 break;
7429
7430 case 13:
7431 //trans + vh flip
7432 //return an error, cannot rotate and VH flip a trans sprite
7433 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7434 break;
7435
7436 case 14:
7437 //pivot and vh flip
7438 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7439 //return error cannot both pivot and vh flip
7440 break;
7441
7442 case 16:
7443 //lit
7444 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7445 rotate_sprite_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7446 break;
7447
7448 case 18:
7449 //pivot, lit
7450 //return an error, cannot both rotate and pivot
7451 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7452 break;
7453
7454 case 20:
7455 //lit + vflip
7456 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7457 rotate_sprite_v_flip_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7458 break;
7459
7460 case 22:
7461 //Pivot, vflip, lit
7462 //return an error, cannot both rotate and pivot
7463 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7464 break;
7465
7466 case 24:
7467 //lit + h flip
7468 //return an error, cannot both rotate and H flip
7469 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
7470 break;
7471
7472 case 26:
7473 //pivot + lit + hflip
7474 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
7475 //return error cannot pivot, lit, and flip
7476 break;
7477
7478 case 28:
7479 //lit + vh flip
7480 //return an error, cannot both rotate and VH flip
7481 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
7482 break;
7483
7484 case 32: //gouraud
7485 //Probably not wort supporting.
7486 //stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7487 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7488 break;
7489
7490 case 0:
7491 //no effect.
7492 1005 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7493 1005 rotate_sprite(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7494 1005 break;
7495
7496 default:
7497
7498 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7499
7500 }
7501 1005 } //end rtated, masked
7502 252924 } //end if masked
7503
7504 else //not masked, and not stretched; just blit
7505 {
7506
7507
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10983 times.
10983 if ( rot == 0 ) //if not rotated
7508 {
7509
2/22
✗ Branch 0 not taken.
✓ Branch 1 taken 5394 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 5589 times.
10983 switch(mode)
7510 {
7511 case 1:
7512 //transparent
7513 5394 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7514 5394 draw_trans_sprite(destBMP, subBmp, dx, dy);
7515 5394 break;
7516
7517
7518 case 2:
7519 //pivot?
7520 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7521 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7522 //Pivoting requires two more args
7523 break;
7524
7525 case 3:
7526 //pivot + trans
7527 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7528 pivot_sprite_trans(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7529 break;
7530
7531 case 4:
7532 //flip v
7533 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7534 draw_sprite_v_flip(destBMP, subBmp, dx, dy);
7535 break;
7536
7537 case 5:
7538 //trans + v flip
7539 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7540 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
7541 break;
7542
7543 case 6:
7544 //pivot + v flip
7545 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7546 pivot_sprite_v_flip(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7547 break;
7548
7549 case 8:
7550 //vlip h
7551 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7552 draw_sprite_h_flip(destBMP, subBmp, dx, dy);
7553 break;
7554
7555 case 9:
7556 //trans + h flip
7557 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7558 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
7559 break;
7560
7561 case 10:
7562 //flip H and pivot
7563 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
7564 //return error cannot pivot and h flip
7565 break;
7566
7567 case 12:
7568 //vh flip
7569 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7570 draw_sprite_vh_flip(destBMP, subBmp, dx, dy);
7571 break;
7572
7573 case 13:
7574 //trans + vh flip
7575 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7576 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
7577 break;
7578
7579 case 14:
7580 //pivot and vh flip
7581 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
7582 //return error cannot both pivot and vh flip
7583 break;
7584
7585 case 16:
7586 //lit
7587 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7588 draw_lit_sprite(destBMP, subBmp, dx, dy, litcolour);
7589 break;
7590
7591 case 18:
7592 //pivot, lit
7593 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7594 pivot_sprite_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
7595 break;
7596
7597 case 20:
7598 //lit + v flip
7599 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7600 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
7601 break;
7602
7603 case 22:
7604 //Pivot, vflip, lit
7605 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7606 pivot_sprite_v_flip_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
7607 break;
7608
7609 case 24:
7610 //lit + h flip
7611 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7612 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
7613 break;
7614
7615 case 26:
7616 //pivot + lit + hflip
7617 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
7618 //return error cannot pivot, lit, and flip
7619 break;
7620
7621 case 28:
7622 //lit + vh flip
7623 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7624 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
7625 break;
7626
7627 case 32: //gouraud
7628 //Probably not wort supporting.
7629 //blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7630 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7631 break;
7632
7633 case 0:
7634 //no effect
7635 5589 blit(sbmp, destBMP, sx, sy, dx, dy, dw, dh);
7636 5589 break;
7637
7638
7639 default:
7640
7641 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7642
7643
7644 }
7645 10983 } //end if not rotated
7646
7647
1/2
✓ Branch 0 taken 10983 times.
✗ Branch 1 not taken.
10983 if ( rot != 0 ) //if rotated
7648 {
7649 switch(mode)
7650 {
7651 case 1:
7652 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);//transparent
7653 rotate_sprite_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7654
7655 break;
7656
7657 case 2:
7658 //pivot?
7659 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7660 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7661 //Pivoting requires two more args
7662 break;
7663
7664 case 3:
7665 //pivot + trans
7666 //return an error, cannot both rotate and pivot
7667 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7668 break;
7669
7670 case 4:
7671 //flip v
7672 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7673 rotate_sprite_v_flip(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7674 break;
7675
7676 case 5:
7677 //trans + v flip
7678 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7679 rotate_sprite_v_flip_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7680 break;
7681
7682 case 6:
7683 //pivot + v flip
7684 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7685 //return an error, cannot both rotate and pivot
7686 break;
7687
7688 case 8:
7689 //flip h
7690 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
7691 //return an error, cannot both rotate and flip H
7692 break;
7693
7694 case 9:
7695 //trans + h flip
7696 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
7697 //return an error, cannot rotate and flip a trans sprite
7698 break;
7699
7700 case 10:
7701 //flip H and pivot
7702 //return error cannot pivot and h flip
7703 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
7704 break;
7705
7706 case 12:
7707 //vh flip
7708 //return an error, cannot rotate and VH flip a trans sprite
7709 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7710 break;
7711
7712 case 13:
7713 //trans + vh flip
7714 //return an error, cannot rotate and VH flip a trans sprite
7715 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7716 break;
7717
7718 case 14:
7719 //pivot and vh flip
7720 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7721 //return error cannot both pivot and vh flip
7722 break;
7723
7724 case 16:
7725 //lit
7726 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7727 rotate_sprite_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7728 break;
7729
7730 case 18:
7731 //pivot, lit
7732 //return an error, cannot both rotate and pivot
7733 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7734 break;
7735
7736 case 20:
7737 //lit + vflip
7738 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7739 rotate_sprite_v_flip_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7740 break;
7741
7742 case 22:
7743 //Pivot, vflip, lit
7744 //return an error, cannot both rotate and pivot
7745 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7746 break;
7747
7748 case 24:
7749 //lit + h flip
7750 //return an error, cannot both rotate and H flip
7751 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
7752 break;
7753
7754 case 26:
7755 //pivot + lit + hflip
7756 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
7757 //return error cannot pivot, lit, and flip
7758 break;
7759
7760 case 28:
7761 //lit + vh flip
7762 //return an error, cannot both rotate and VH flip
7763 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
7764 break;
7765
7766 case 32: //gouraud
7767 //Probably not wort supporting.
7768 //blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7769 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7770 break;
7771
7772 case 0:
7773 //no effect.
7774 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7775 rotate_sprite(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7776 break;
7777
7778 default:
7779
7780 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7781
7782 }
7783 } //end if rotated
7784 } //end if not masked
7785 } //end if not stretched
7786
7787 //cleanup
7788
2/2
✓ Branch 0 taken 26562 times.
✓ Branch 1 taken 238947 times.
265509 if(subBmp)
7789 {
7790 //script_drawing_commands.ReleaseSubBitmap(subBmp); //purge the temporary bitmap.
7791 26562 destroy_bitmap(subBmp);
7792 26562 }
7793
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 265509 times.
265509 if (sbmp != sourceBitmap)
7794 {
7795 destroy_bitmap(sbmp);
7796 }
7797 265509 }
7798
7799
7800
7801 113329 void bmp_do_blittor(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
7802 {
7803 /*
7804 //sdci[1]=layer
7805 //sdci[2]=bitmap target
7806 //
7807 // -2 is the current Render Target
7808 // -1, this is the screen (framebuf).
7809 // 0: Render target 0
7810 // 1: Render target 1
7811 // 2: Render target 2
7812 // 3: Render target 3
7813 // 4: Render target 4
7814 // 5: Render target 5
7815 // 6: Render target 6
7816 // Otherwise: The pointer to a bitmap.
7817
7818 //sdci[3]=sourcex
7819 //sdci[4]=sourcey
7820 //sdci[5]=sourcew
7821 //sdci[6]=sourceh
7822 //sdci[7]=destx
7823 //sdci[8]=desty
7824 //sdci[9]=destw
7825 //sdci[10]=desth
7826 //sdci[11]=rotation/angle
7827 //scdi[12] = pivot cx
7828 //sdci[13] = pivot cy
7829 //scdi[14] = effect flags
7830 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
7831
7832 // ZScript-side constant values:
7833 const int32_t BITDX_NORMAL = 0;
7834 const int32_t BITDX_TRANS = 1; //Translucent
7835 const int32_t BITDX_PIVOT = 2; //THe sprite will rotate at a specific point, instead of its center.
7836 const int32_t BITDX_HFLIP = 4; //Horizontal Flip
7837 const int32_t BITDX_VFLIP = 8; //Vertical Flip.
7838 //Note: Some modes cannot be combined. if a combination is not supported, an error
7839 // detailing this will be shown in allegro.log.
7840
7841 //scdi[15] = litcolour
7842 //The allegro docs are wrong. The params are: rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7843 //not rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
7844
7845 //sdci[16]=mask
7846
7847 */
7848
7849 113329 int32_t srcyoffset = yoffset, srcxoffset = xoffset;
7850
7851 113329 int32_t usr_bitmap_index = sdci[2];
7852 339987 auto [bitmapIndex, is_user_bitmap] = resolveScriptingBitmapId(usr_bitmap_index);
7853
7854 113329 int32_t sx = sdci[3]/10000;
7855 113329 int32_t sy = sdci[4]/10000;
7856 113329 int32_t sw = sdci[5]/10000;
7857 113329 int32_t sh = sdci[6]/10000;
7858 113329 int32_t dx = sdci[7]/10000;
7859 113329 int32_t dy = sdci[8]/10000;
7860 113329 int32_t dw = sdci[9]/10000;
7861 113329 int32_t dh = sdci[10]/10000;
7862 113329 float rot = sdci[11]/10000;
7863 113329 int32_t cx = sdci[12]/10000;
7864 113329 int32_t cy = sdci[13]/10000;
7865 113329 int32_t mode = sdci[14]/10000;
7866 113329 int32_t litcolour = sdci[15]/10000;
7867 113329 bool masked = (sdci[16] != 0);
7868
7869 113329 int32_t ref = 0;
7870
7871
1/2
✓ Branch 0 taken 113329 times.
✗ Branch 1 not taken.
113329 if (get_qr(qr_BROKEN_SCRIPTS_BITMAP_DRAW_ORIGIN))
7872 {
7873
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 113326 times.
113329 if (is_user_bitmap)
7874 113326 srcyoffset = 0;
7875
2/4
✓ Branch 0 taken 113329 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 113329 times.
113329 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
7876
3/4
✓ Branch 0 taken 113329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 113326 times.
113329 if ( (bitmapIndex) != -2 && (bitmapIndex) != -1 ) srcyoffset = 0; //Don't crop.
7877
7878 113329 dx += xoffset;
7879 113329 dy += yoffset;
7880
7881 113329 sx += srcxoffset;
7882 113329 sy += srcyoffset;
7883 113329 }
7884 else
7885 {
7886 dx += xoffset;
7887 dy += yoffset;
7888
7889 sx += secondary_draw_origin_xoff;
7890 sy += secondary_draw_origin_yoff;
7891 }
7892
7893 113329 ref = sdci[DRAWCMD_BMP_TARGET];
7894
7895
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 113329 times.
113329 if ( ref <= 0 )
7896 {
7897 Z_scripterrlog("bitmap->blit() wanted to use to an invalid source bitmap id: %d. Aborting.\n", ref);
7898 return;
7899 }
7900 113329 BITMAP *sourceBitmap = FFCore.GetScriptBitmap(ref); //This can be the screen, as -1.
7901
1/2
✓ Branch 0 taken 113329 times.
✗ Branch 1 not taken.
113329 if(!sourceBitmap)
7902 {
7903 Z_message("Warning: blit(%d) source bitmap contains invalid data or is not initialized.\n", ref);
7904 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
7905 return;
7906 }
7907
7908 113329 BITMAP *destBMP=NULL;
7909
7910
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 113326 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
113329 switch(bitmapIndex)
7911 {
7912 case -2:
7913 {
7914 int32_t curr_rt = zscriptDrawingRenderTarget->GetCurrentRenderTarget();
7915 if ( curr_rt >= 0 && curr_rt < 7 )
7916 destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex); //Drawing to the current RenderTarget.
7917 else destBMP = bmp; //screen
7918 break;
7919 }
7920 case -1:
7921 3 destBMP = bmp; //this is framebuf, by default
7922 3 break;
7923 //zscriptDrawingRenderTarget->SetCurrentRenderTarget(bitmapIndex);
7924 //destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex);
7925 //destBMP = framebuf; //Drawing to the screen.
7926 //break;
7927
7928 //1 through 6 are the old system bitmaps (Render Targets)
7929 case 0:
7930 case 1:
7931 case 2:
7932 case 3:
7933 case 4:
7934 case 5:
7935 case 6:
7936 {
7937 //This gets a render target.
7938 //destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex); break;
7939
7940 destBMP = zscriptDrawingRenderTarget->GetTargetBitmap(bitmapIndex);
7941 //sdci[18] = bitmapIndex;
7942 break;
7943 }
7944 //Otherwise, we are using a user-created bitmap, so, get that pointer insted.
7945 default:
7946 {
7947 113326 auto& usr_bitmap = scb.get(usr_bitmap_index);
7948 113326 destBMP = usr_bitmap.u_bmp;
7949 //sdci[18] = usr_bitmap_index;
7950
1/2
✓ Branch 0 taken 113326 times.
✗ Branch 1 not taken.
113326 if ( !usr_bitmap.u_bmp )
7951 {
7952 Z_scripterrlog("Target for bitmap->Blit is uninitialised. Aborting.\n");
7953 break;
7954 }
7955 }
7956 113326 }
7957
7958
1/2
✓ Branch 0 taken 113329 times.
✗ Branch 1 not taken.
113329 if (!destBMP)
7959 {
7960 Z_message("Warning: blit(%d) destination bitmap contains invalid data or is not initialized.\n", bitmapIndex);
7961 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
7962 return;
7963 }
7964
7965
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 113329 times.
113329 bool stretched = (sw != dw || sh != dh);
7966
7967 113329 BITMAP* newDest = sourceBitmap;
7968 113329 BITMAP* newSource = destBMP; //Flip them.
7969
7970 113329 BITMAP* subBmp = 0;
7971
7972
2/4
✓ Branch 0 taken 113329 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 113329 times.
113329 if(rot != 0 || mode != 0)
7973 {
7974 subBmp = create_bitmap_ex(8,sourceBitmap->w, sourceBitmap->h);//script_drawing_commands.AquireSubBitmap(dw, dh);
7975 clear_bitmap(subBmp);
7976
7977 if(!subBmp)
7978 {
7979 Z_scripterrlog("bitmap->Blit failed to create a sub-bitmap to use for %s. Aborting.\n", "rotation");
7980 return;
7981 }
7982 }
7983
7984
3/4
✓ Branch 0 taken 113329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 113326 times.
113329 if (sx + sw > destBMP->w || sy + sh > destBMP->h)
7985 {
7986 3 newSource = create_bitmap_ex(8, sw, sh);
7987 3 clear_bitmap(newSource);
7988 3 blit(destBMP, newSource, sx, sy, 0, 0, std::min(destBMP->w-sx, sw), std::min(destBMP->h-sy, sh));
7989 3 sx = 0;
7990 3 sy = 0;
7991 3 }
7992 //dx = dx + xoffset; //don't do this here!
7993 //dy = dy + yoffset; //Nor this. It auto-offsets the bitmap by +56. Hmm. The fix that gleeok made isn't being applied to these functions. -Z ( 17th April, 2019 )
7994
7995
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 113329 times.
113329 if(stretched)
7996 {
7997 if(masked)
7998 { //stretched and masked
7999 if ( rot == 0 )
8000 { //if not rotated
8001 switch(mode)
8002 {
8003 case 1:
8004 //transparent
8005 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8006 draw_trans_sprite(newDest, subBmp, dx, dy);
8007 break;
8008
8009
8010 case 2:
8011 //pivot?
8012 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8013 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8014 //Pivoting requires two more args
8015 break;
8016
8017 case 3:
8018 //pivot + trans
8019 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8020 pivot_sprite_trans(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8021 break;
8022
8023 case 4:
8024 //flip v
8025 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8026 draw_sprite_v_flip(newDest, subBmp, dx, dy);
8027 break;
8028
8029 case 5:
8030 //trans + v flip
8031 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8032 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
8033 break;
8034
8035 case 6:
8036 //pivot + v flip
8037 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8038 pivot_sprite_v_flip(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8039 break;
8040
8041 case 8:
8042 //vlip h
8043 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8044 draw_sprite_h_flip(newDest, subBmp, dx, dy);
8045 break;
8046
8047 case 9:
8048 //trans + h flip
8049 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8050 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
8051 break;
8052
8053 case 10:
8054 //flip H and pivot
8055 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8056 //return error cannot pivot and h flip
8057 break;
8058
8059 case 12:
8060 //vh flip
8061 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8062 draw_sprite_vh_flip(newDest, subBmp, dx, dy);
8063 break;
8064
8065 case 13:
8066 //trans + vh flip
8067 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8068 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
8069 break;
8070
8071 case 14:
8072 //pivot and vh flip
8073 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8074 //return error cannot both pivot and vh flip
8075 break;
8076
8077 case 16:
8078 //lit
8079 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8080 draw_lit_sprite(newDest, subBmp, dx, dy, litcolour);
8081 break;
8082
8083 case 18:
8084 //pivot, lit
8085 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8086 pivot_sprite_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8087 break;
8088
8089 case 20:
8090 //lit + v flip
8091 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8092 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
8093 break;
8094
8095 case 22:
8096 //Pivot, vflip, lit
8097 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8098 pivot_sprite_v_flip_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8099 break;
8100
8101 case 24:
8102 //lit + h flip
8103 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8104 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
8105 break;
8106
8107 case 26:
8108 //pivot + lit + hflip
8109 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
8110 //return error cannot pivot, lit, and flip
8111 break;
8112
8113 case 28:
8114 //lit + vh flip
8115 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8116 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
8117 break;
8118
8119 case 32: //gouraud
8120 //Probably not wort supporting.
8121 //masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8122 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8123 break;
8124
8125 case 0:
8126 //no effect
8127 masked_stretch_blit(newSource, newDest, sx, sy, sw, sh, dx, dy, dw, dh);
8128 break;
8129
8130
8131 default:
8132 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8133
8134
8135 }
8136 } //end if not rotated
8137
8138 if ( rot != 0 ) //if rotated
8139 {
8140 switch(mode)
8141 {
8142 case 1:
8143 //transparent
8144 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8145 rotate_sprite_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8146
8147 break;
8148
8149 case 2:
8150 //pivot?
8151 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8152 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8153 //Pivoting requires two more args
8154 break;
8155
8156 case 3:
8157 //pivot + trans
8158 //return an error, cannot both rotate and pivot
8159 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8160 break;
8161
8162 case 4:
8163 //flip v
8164 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8165 rotate_sprite_v_flip(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8166 break;
8167
8168 case 5:
8169 //trans + v flip
8170 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8171 rotate_sprite_v_flip_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8172 break;
8173
8174 case 6:
8175 //pivot + v flip
8176 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8177 //return an error, cannot both rotate and pivot
8178 break;
8179
8180 case 8:
8181 //flip h
8182 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
8183 //return an error, cannot both rotate and flip H
8184 break;
8185
8186 case 9:
8187 //trans + h flip
8188 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
8189 //return an error, cannot rotate and flip a trans sprite
8190 break;
8191
8192 case 10:
8193 //flip H and pivot
8194 //return error cannot pivot and h flip
8195 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8196 break;
8197
8198 case 12:
8199 //vh flip
8200 //return an error, cannot rotate and VH flip a trans sprite
8201 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
8202 break;
8203
8204 case 13:
8205 //trans + vh flip
8206 //return an error, cannot rotate and VH flip a trans sprite
8207 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
8208 break;
8209
8210 case 14:
8211 //pivot and vh flip
8212 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
8213 //return error cannot both pivot and vh flip
8214 break;
8215
8216 case 16:
8217 //lit
8218 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8219 rotate_sprite_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
8220 break;
8221
8222 case 18:
8223 //pivot, lit
8224 //return an error, cannot both rotate and pivot
8225 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8226 break;
8227
8228 case 20:
8229 //lit + vflip
8230 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8231 rotate_sprite_v_flip_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
8232 break;
8233
8234 case 22:
8235 //Pivot, vflip, lit
8236 //return an error, cannot both rotate and pivot
8237 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
8238 break;
8239
8240 case 24:
8241 //lit + h flip
8242 //return an error, cannot both rotate and H flip
8243 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
8244 break;
8245
8246 case 26:
8247 //pivot + lit + hflip
8248 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
8249 //return error cannot pivot, lit, and flip
8250 break;
8251
8252 case 28:
8253 //lit + vh flip
8254 //return an error, cannot both rotate and VH flip
8255 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8256 break;
8257
8258 case 32: //gouraud
8259 //Probably not wort supporting.
8260 //masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8261 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8262 break;
8263
8264 case 0:
8265 //no effect.
8266 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8267 rotate_sprite(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8268 break;
8269
8270 default:
8271 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8272
8273 }
8274 }
8275 } //end if stretched and masked
8276
8277 else //stretched, not masked
8278 {
8279
8280
8281 if ( rot == 0 ) //if not rotated
8282 {
8283 switch(mode)
8284 {
8285 case 1:
8286 //transparent
8287 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8288 draw_trans_sprite(newDest, subBmp, dx, dy);
8289 break;
8290
8291
8292 case 2:
8293 //pivot?
8294 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8295 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8296 //Pivoting requires two more args
8297 break;
8298
8299 case 3:
8300 //pivot + trans
8301 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8302 pivot_sprite_trans(newDest, subBmp, dx,dy, cx, cy, degrees_to_fixed(rot));
8303 break;
8304
8305 case 4:
8306 //flip v
8307 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8308 draw_sprite_v_flip(newDest, subBmp, dx, dy);
8309 break;
8310
8311 case 5:
8312 //trans + v flip
8313 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8314 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
8315 break;
8316
8317 case 6:
8318 //pivot + v flip
8319 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8320 pivot_sprite_v_flip(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8321 break;
8322
8323 case 8:
8324 //vlip h
8325 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8326 draw_sprite_h_flip(newDest, subBmp, dx, dy);
8327 break;
8328
8329 case 9:
8330 //trans + h flip
8331 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8332 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
8333 break;
8334
8335 case 10:
8336 //flip H and pivot
8337 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8338 //return error cannot pivot and h flip
8339 break;
8340
8341 case 12:
8342 //vh flip
8343 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8344 draw_sprite_vh_flip(newDest, subBmp, dx, dy);
8345 break;
8346
8347 case 13:
8348 //trans + vh flip
8349 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8350 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
8351 break;
8352
8353 case 14:
8354 //pivot and vh flip
8355 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8356 //return error cannot both pivot and vh flip
8357 break;
8358
8359 case 16:
8360 //lit
8361 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8362 draw_lit_sprite(newDest, subBmp, dx, dy, litcolour);
8363 break;
8364
8365 case 18:
8366 //pivot, lit
8367 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8368 pivot_sprite_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8369 break;
8370
8371 case 20:
8372 //lit + v flip
8373 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8374 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
8375 break;
8376
8377 case 22:
8378 //Pivot, vflip, lit
8379 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8380 pivot_sprite_v_flip_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8381 break;
8382
8383 case 24:
8384 //lit + h flip
8385 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8386 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
8387 break;
8388
8389 case 26:
8390 //pivot + lit + hflip
8391 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
8392 //return error cannot pivot, lit, and flip
8393 break;
8394
8395 case 28:
8396 //lit + vh flip
8397 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8398 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
8399 break;
8400
8401 case 32: //gouraud
8402 //Probably not wort supporting.
8403 //stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8404 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8405 break;
8406
8407 case 0:
8408 //no effect
8409 stretch_blit(newSource, newDest, sx, sy, sw, sh, dx, dy, dw, dh);
8410 break;
8411
8412
8413 default:
8414 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8415
8416
8417 }
8418 } //end if not rotated
8419
8420 if ( rot != 0 ) //if rotated
8421 {
8422 switch(mode)
8423 {
8424 case 1:
8425 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
8426 rotate_sprite_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8427
8428 break;
8429
8430 case 2:
8431 //pivot?
8432 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8433 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8434 //Pivoting requires two more args
8435 break;
8436
8437 case 3:
8438 //pivot + trans
8439 //return an error, cannot both rotate and pivot
8440 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8441 break;
8442
8443 case 4:
8444 //flip v
8445 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8446 rotate_sprite_v_flip(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8447 break;
8448
8449 case 5:
8450 //trans + v flip
8451 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8452 rotate_sprite_v_flip_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8453 break;
8454
8455 case 6:
8456 //pivot + v flip
8457 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8458 //return an error, cannot both rotate and pivot
8459 break;
8460
8461 case 8:
8462 //flip h
8463 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
8464 //return an error, cannot both rotate and flip H
8465 break;
8466
8467 case 9:
8468 //trans + h flip
8469 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
8470 //return an error, cannot rotate and flip a trans sprite
8471 break;
8472
8473 case 10:
8474 //flip H and pivot
8475 //return error cannot pivot and h flip
8476 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8477 break;
8478
8479 case 12:
8480 //vh flip
8481 //return an error, cannot rotate and VH flip a trans sprite
8482 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
8483 break;
8484
8485 case 13:
8486 //trans + vh flip
8487 //return an error, cannot rotate and VH flip a trans sprite
8488 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
8489 break;
8490
8491 case 14:
8492 //pivot and vh flip
8493 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
8494 //return error cannot both pivot and vh flip
8495 break;
8496
8497 case 16:
8498 //lit
8499 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
8500 rotate_sprite_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
8501 break;
8502
8503 case 18:
8504 //pivot, lit
8505 //return an error, cannot both rotate and pivot
8506 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8507 break;
8508
8509 case 20:
8510 //lit + vflip
8511 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
8512 rotate_sprite_v_flip_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
8513 break;
8514
8515 case 22:
8516 //Pivot, vflip, lit
8517 //return an error, cannot both rotate and pivot
8518 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
8519 break;
8520
8521 case 24:
8522 //lit + h flip
8523 //return an error, cannot both rotate and H flip
8524 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
8525 break;
8526
8527 case 26:
8528 //pivot + lit + hflip
8529 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
8530 //return error cannot pivot, lit, and flip
8531 break;
8532
8533 case 28:
8534 //lit + vh flip
8535 //return an error, cannot both rotate and VH flip
8536 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8537 break;
8538
8539 case 32: //gouraud
8540 //Probably not wort supporting.
8541 //stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8542 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8543 break;
8544
8545 case 0:
8546 //no effect.
8547 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8548 rotate_sprite(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8549 break;
8550
8551 default:
8552 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8553
8554 }
8555 }
8556
8557 } //end if stretched, but not masked
8558 }
8559 else //not stretched
8560 {
8561
8562
2/2
✓ Branch 0 taken 113326 times.
✓ Branch 1 taken 3 times.
113329 if(masked) //if masked, but not stretched
8563 {
8564
8565
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 113326 times.
113326 if ( rot == 0 ) //if not rotated
8566 {
8567
1/22
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 113326 times.
113326 switch(mode)
8568 {
8569 case 1:
8570 //transparent
8571 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8572 draw_trans_sprite(newDest, subBmp, dx, dy);
8573 break;
8574
8575
8576 case 2:
8577 //pivot?
8578 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8579 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8580 //Pivoting requires two more args
8581 break;
8582
8583 case 3:
8584 //pivot + trans
8585 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8586 pivot_sprite_trans(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8587 break;
8588
8589 case 4:
8590 //flip v
8591 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8592 draw_sprite_v_flip(newDest, subBmp, dx, dy);
8593 break;
8594
8595 case 5:
8596 //trans + v flip
8597 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8598 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
8599 break;
8600
8601 case 6:
8602 //pivot + v flip
8603 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8604 pivot_sprite_v_flip(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8605 break;
8606
8607 case 8:
8608 //vlip h
8609 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8610 draw_sprite_h_flip(newDest, subBmp, dx, dy);
8611 break;
8612
8613 case 9:
8614 //trans + h flip
8615 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8616 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
8617 break;
8618
8619 case 10:
8620 //flip H and pivot
8621 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8622 //return error cannot pivot and h flip
8623 break;
8624
8625 case 12:
8626 //vh flip
8627 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8628 draw_sprite_vh_flip(newDest, subBmp, dx, dy);
8629 break;
8630
8631 case 13:
8632 //trans + vh flip
8633 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8634 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
8635 break;
8636
8637 case 14:
8638 //pivot and vh flip
8639 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8640 //return error cannot both pivot and vh flip
8641 break;
8642
8643 case 16:
8644 //lit
8645 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8646 draw_lit_sprite(newDest, subBmp, dx, dy, litcolour);
8647 break;
8648
8649 case 18:
8650 //pivot, lit
8651 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8652 pivot_sprite_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8653 break;
8654
8655 case 20:
8656 //lit + v flip
8657 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8658 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
8659 break;
8660
8661 case 22:
8662 //Pivot, vflip, lit
8663 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8664 pivot_sprite_v_flip_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8665 break;
8666
8667 case 24:
8668 //lit + h flip
8669 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8670 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
8671 break;
8672
8673 case 26:
8674 //pivot + lit + hflip
8675 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
8676 //return error cannot pivot, lit, and flip
8677 break;
8678
8679 case 28:
8680 //lit + vh flip
8681 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8682 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
8683 break;
8684
8685 case 32: //gouraud
8686 //Probably not wort supporting.
8687 //stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8688 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8689 break;
8690
8691 case 0:
8692 //no effect
8693 113326 masked_blit(newSource, newDest, sx, sy, dx, dy, dw, dh);
8694 113326 break;
8695
8696
8697 default:
8698 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8699
8700
8701 }
8702 113326 } //end if not rotated
8703
8704
1/2
✓ Branch 0 taken 113326 times.
✗ Branch 1 not taken.
113326 if ( rot != 0 ) //if rotated
8705 {
8706 switch(mode)
8707 {
8708 case 1:
8709 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh); //transparent
8710 rotate_sprite_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8711
8712 break;
8713
8714 case 2:
8715 //pivot?
8716 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8717 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8718 //Pivoting requires two more args
8719 break;
8720
8721 case 3:
8722 //pivot + trans
8723 //return an error, cannot both rotate and pivot
8724 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8725 break;
8726
8727 case 4:
8728 //flip v
8729 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8730 rotate_sprite_v_flip(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8731 break;
8732
8733 case 5:
8734 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh); //trans + v flip
8735 rotate_sprite_v_flip_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8736 break;
8737
8738 case 6:
8739 //pivot + v flip
8740 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8741 //return an error, cannot both rotate and pivot
8742 break;
8743
8744 case 8:
8745 //flip h
8746 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
8747 //return an error, cannot both rotate and flip H
8748 break;
8749
8750 case 9:
8751 //trans + h flip
8752 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
8753 //return an error, cannot rotate and flip a trans sprite
8754 break;
8755
8756 case 10:
8757 //flip H and pivot
8758 //return error cannot pivot and h flip
8759 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8760 break;
8761
8762 case 12:
8763 //vh flip
8764 //return an error, cannot rotate and VH flip a trans sprite
8765 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
8766 break;
8767
8768 case 13:
8769 //trans + vh flip
8770 //return an error, cannot rotate and VH flip a trans sprite
8771 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
8772 break;
8773
8774 case 14:
8775 //pivot and vh flip
8776 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
8777 //return error cannot both pivot and vh flip
8778 break;
8779
8780 case 16:
8781 //lit
8782 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8783 rotate_sprite_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
8784 break;
8785
8786 case 18:
8787 //pivot, lit
8788 //return an error, cannot both rotate and pivot
8789 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8790 break;
8791
8792 case 20:
8793 //lit + vflip
8794 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8795 rotate_sprite_v_flip_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
8796 break;
8797
8798 case 22:
8799 //Pivot, vflip, lit
8800 //return an error, cannot both rotate and pivot
8801 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
8802 break;
8803
8804 case 24:
8805 //lit + h flip
8806 //return an error, cannot both rotate and H flip
8807 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
8808 break;
8809
8810 case 26:
8811 //pivot + lit + hflip
8812 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
8813 //return error cannot pivot, lit, and flip
8814 break;
8815
8816 case 28:
8817 //lit + vh flip
8818 //return an error, cannot both rotate and VH flip
8819 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8820 break;
8821
8822 case 32: //gouraud
8823 //Probably not wort supporting.
8824 //stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8825 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8826 break;
8827
8828 case 0:
8829 //no effect.
8830 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8831 rotate_sprite(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8832 break;
8833
8834 default:
8835 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8836
8837 }
8838 } //end rtated, masked
8839 113326 } //end if masked
8840
8841 else //not masked, and not stretched; just blit
8842 {
8843
8844
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if ( rot == 0 ) //if not rotated
8845 {
8846
1/22
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 3 times.
3 switch(mode)
8847 {
8848 case 1:
8849 //transparent
8850 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8851 draw_trans_sprite(newDest, subBmp, dx, dy);
8852 break;
8853
8854
8855 case 2:
8856 //pivot?
8857 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8858 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8859 //Pivoting requires two more args
8860 break;
8861
8862 case 3:
8863 //pivot + trans
8864 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8865 pivot_sprite_trans(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8866 break;
8867
8868 case 4:
8869 //flip v
8870 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8871 draw_sprite_v_flip(newDest, subBmp, dx, dy);
8872 break;
8873
8874 case 5:
8875 //trans + v flip
8876 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8877 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
8878 break;
8879
8880 case 6:
8881 //pivot + v flip
8882 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8883 pivot_sprite_v_flip(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8884 break;
8885
8886 case 8:
8887 //vlip h
8888 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8889 draw_sprite_h_flip(newDest, subBmp, dx, dy);
8890 break;
8891
8892 case 9:
8893 //trans + h flip
8894 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8895 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
8896 break;
8897
8898 case 10:
8899 //flip H and pivot
8900 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8901 //return error cannot pivot and h flip
8902 break;
8903
8904 case 12:
8905 //vh flip
8906 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8907 draw_sprite_vh_flip(newDest, subBmp, dx, dy);
8908 break;
8909
8910 case 13:
8911 //trans + vh flip
8912 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8913 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
8914 break;
8915
8916 case 14:
8917 //pivot and vh flip
8918 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8919 //return error cannot both pivot and vh flip
8920 break;
8921
8922 case 16:
8923 //lit
8924 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8925 draw_lit_sprite(newDest, subBmp, dx, dy, litcolour);
8926 break;
8927
8928 case 18:
8929 //pivot, lit
8930 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8931 pivot_sprite_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8932 break;
8933
8934 case 20:
8935 //lit + v flip
8936 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8937 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
8938 break;
8939
8940 case 22:
8941 //Pivot, vflip, lit
8942 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8943 pivot_sprite_v_flip_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8944 break;
8945
8946 case 24:
8947 //lit + h flip
8948 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8949 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
8950 break;
8951
8952 case 26:
8953 //pivot + lit + hflip
8954 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
8955 //return error cannot pivot, lit, and flip
8956 break;
8957
8958 case 28:
8959 //lit + vh flip
8960 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8961 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
8962 break;
8963
8964 case 32: //gouraud
8965 //Probably not wort supporting.
8966 //blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8967 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8968 break;
8969
8970 case 0:
8971 //no effect
8972 3 blit(newSource, newDest, sx, sy, dx, dy, dw, dh);
8973 3 break;
8974
8975
8976 default:
8977 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8978
8979
8980 }
8981 3 } //end if not rotated
8982
8983
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if ( rot != 0 ) //if rotated
8984 {
8985 switch(mode)
8986 {
8987 case 1:
8988 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);//transparent
8989 rotate_sprite_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8990
8991 break;
8992
8993 case 2:
8994 //pivot?
8995 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8996 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8997 //Pivoting requires two more args
8998 break;
8999
9000 case 3:
9001 //pivot + trans
9002 //return an error, cannot both rotate and pivot
9003 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
9004 break;
9005
9006 case 4:
9007 //flip v
9008 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9009 rotate_sprite_v_flip(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
9010 break;
9011
9012 case 5:
9013 //trans + v flip
9014 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9015 rotate_sprite_v_flip_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
9016 break;
9017
9018 case 6:
9019 //pivot + v flip
9020 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
9021 //return an error, cannot both rotate and pivot
9022 break;
9023
9024 case 8:
9025 //flip h
9026 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
9027 //return an error, cannot both rotate and flip H
9028 break;
9029
9030 case 9:
9031 //trans + h flip
9032 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
9033 //return an error, cannot rotate and flip a trans sprite
9034 break;
9035
9036 case 10:
9037 //flip H and pivot
9038 //return error cannot pivot and h flip
9039 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
9040 break;
9041
9042 case 12:
9043 //vh flip
9044 //return an error, cannot rotate and VH flip a trans sprite
9045 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
9046 break;
9047
9048 case 13:
9049 //trans + vh flip
9050 //return an error, cannot rotate and VH flip a trans sprite
9051 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
9052 break;
9053
9054 case 14:
9055 //pivot and vh flip
9056 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
9057 //return error cannot both pivot and vh flip
9058 break;
9059
9060 case 16:
9061 //lit
9062 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9063 rotate_sprite_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
9064 break;
9065
9066 case 18:
9067 //pivot, lit
9068 //return an error, cannot both rotate and pivot
9069 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
9070 break;
9071
9072 case 20:
9073 //lit + vflip
9074 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9075 rotate_sprite_v_flip_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
9076 break;
9077
9078 case 22:
9079 //Pivot, vflip, lit
9080 //return an error, cannot both rotate and pivot
9081 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
9082 break;
9083
9084 case 24:
9085 //lit + h flip
9086 //return an error, cannot both rotate and H flip
9087 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
9088 break;
9089
9090 case 26:
9091 //pivot + lit + hflip
9092 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
9093 //return error cannot pivot, lit, and flip
9094 break;
9095
9096 case 28:
9097 //lit + vh flip
9098 //return an error, cannot both rotate and VH flip
9099 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
9100 break;
9101
9102 case 32: //gouraud
9103 //Probably not wort supporting.
9104 //blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9105 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
9106 break;
9107
9108 case 0:
9109 //no effect.
9110 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9111 rotate_sprite(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
9112 break;
9113
9114 default:
9115 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
9116
9117 }
9118 } //end if rotated
9119 } //end if not masked
9120 } //end if not stretched
9121
9122 //cleanup
9123
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 113329 times.
113329 if(subBmp)
9124 {
9125 //script_drawing_commands.ReleaseSubBitmap(subBmp); //purge the temporary bitmap.
9126 destroy_bitmap(subBmp);
9127 }
9128
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 113326 times.
113329 if(newSource != destBMP)
9129 {
9130 3 destroy_bitmap(newSource);
9131 3 }
9132 113329 }
9133
9134 void do_tileblit(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool is_bmp, char const* funcstr)
9135 {
9136 /*
9137 //sdci[1]=layer
9138 //sdci[2]=tile
9139 //sdci[3]=cset
9140 //sdci[4]=sourcex
9141 //sdci[5]=sourcey
9142 //sdci[6]=sourcew
9143 //sdci[7]=sourceh
9144 //sdci[8]=destx
9145 //sdci[9]=desty
9146 //sdci[10]=destw
9147 //sdci[11]=desth
9148 //sdci[12]=rotation/angle
9149 //scdi[13] = pivot cx
9150 //sdci[14] = pivot cy
9151 //scdi[15] = effect flags
9152
9153 // ZScript-side constant values:
9154 const int32_t BITDX_NORMAL = 0;
9155 const int32_t BITDX_TRANS = 1; //Translucent
9156 const int32_t BITDX_PIVOT = 2; //THe sprite will rotate at a specific point, instead of its center.
9157 const int32_t BITDX_HFLIP = 4; //Horizontal Flip
9158 const int32_t BITDX_VFLIP = 8; //Vertical Flip.
9159 //Note: Some modes cannot be combined. if a combination is not supported, an error
9160 // detailing this will be shown in allegro.log.
9161
9162 //scdi[16] = litcolour
9163 //The allegro docs are wrong. The params are: rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
9164 //not rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
9165
9166 //sdci[17]=mask
9167 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
9168
9169 */
9170
9171 int32_t tile = sdci[2]/10000;
9172 int32_t cset = WRAP_CS(sdci[3]/10000);
9173
9174 int32_t sx = sdci[4]/10000;
9175 int32_t sy = sdci[5]/10000;
9176 int32_t sw = sdci[6]/10000;
9177 //Z_scripterrlog("sh is: %d\n",sdci[5]/10000);
9178 int32_t sh = sdci[7]/10000;
9179 //Z_scripterrlog("sh is: %d\n",sdci[6]/10000);
9180 int32_t dx = sdci[8]/10000;
9181 int32_t dy = sdci[9]/10000;
9182 int32_t dw = sdci[10]/10000;
9183 int32_t dh = sdci[11]/10000;
9184 float rot = sdci[12]/10000;
9185 int32_t cx = sdci[13]/10000;
9186 int32_t cy = sdci[14]/10000;
9187 int32_t mode = sdci[15]/10000;
9188 int32_t litcolour = sdci[16]/10000;
9189 bool masked = (sdci[17] != 0);
9190
9191 int32_t ref = 0;
9192
9193 if ( is_bmp && (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
9194 //Do we need to also check the render target and do the same thing if the
9195 //dest == -2 and the render target is not RT_SCREEN?
9196 dx += xoffset;
9197 dy += yoffset;
9198
9199 BITMAP *destbmp = nullptr;
9200 if(is_bmp)
9201 {
9202 ref = sdci[DRAWCMD_BMP_TARGET];
9203
9204 if ( ref <= 0 )
9205 {
9206 Z_scripterrlog("%s wanted to use to an invalid dest bitmap id: %d. Aborting.\n", funcstr, ref);
9207 return;
9208 }
9209 destbmp = FFCore.GetScriptBitmap(ref);
9210 if(!destbmp)
9211 {
9212 Z_message("Warning: %s dest bitmap %d contains invalid data or is not initialized.\n", ref);
9213 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
9214 return;
9215 }
9216 }
9217 else destbmp = bmp;
9218
9219 bool stretched = (sw != dw || sh != dh);
9220
9221 BITMAP* srcbmp = create_bitmap_ex(8, sw, sh);
9222 //Draw tiles to srcbmp
9223 {
9224 clear_bitmap(srcbmp);
9225 int tx = 0, ty = 0;
9226 if(sx < 0)
9227 tx = (sx-15)/16;
9228 else if(sx > 15)
9229 tx = sx/16;
9230 if(sy < 0)
9231 ty = (sy-15)/16;
9232 else if(sy > 15)
9233 ty = sy/16;
9234
9235 int gxoff = -wrap(sx,0,15), gyoff = -wrap(sy,0,15);
9236 for(int ix = 0; ix <= sw; ix += 16)
9237 {
9238 for(int iy = 0; iy <= sh; iy += 16)
9239 {
9240 int t = tile+(tx+ix/16);
9241 int rowdiff = TILEROW(t) - TILEROW(tile);
9242 t += rowdiff * (sh/16) * TILES_PER_ROW;
9243 t += (ty+iy/16)*TILES_PER_ROW;
9244 overtile16(srcbmp, t, ix+gxoff, iy+gyoff, cset, 0);
9245 }
9246 }
9247
9248 sx = sy = 0;
9249 }
9250
9251 BITMAP* subBmp = nullptr;
9252
9253 if(rot != 0 || mode != 0)
9254 {
9255 subBmp = create_bitmap_ex(8,destbmp->w, destbmp->h);//script_drawing_commands.AquireSubBitmap(dw, dh);
9256 clear_bitmap(subBmp);
9257
9258 if(!subBmp)
9259 {
9260 Z_scripterrlog("%s failed to create a sub-bitmap to use for %s. Aborting.\n", funcstr, "rotation");
9261 return;
9262 }
9263 }
9264
9265 //dx = dx + xoffset; //don't do this here!
9266 //dy = dy + yoffset; //Nor this. It auto-offsets the bitmap by +56. Hmm. The fix that gleeok made isn't being applied to these functions. -Z ( 17th April, 2019 )
9267
9268 if(stretched)
9269 {
9270 if(masked)
9271 { //stretched and masked
9272 if ( rot == 0 )
9273 { //if not rotated
9274 switch(mode)
9275 {
9276 case 1:
9277 //transparent
9278 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9279 draw_trans_sprite(destbmp, subBmp, dx, dy);
9280 break;
9281
9282
9283 case 2:
9284 //pivot?
9285 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9286 pivot_sprite(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9287 //Pivoting requires two more args
9288 break;
9289
9290 case 3:
9291 //pivot + trans
9292 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9293 pivot_sprite_trans(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9294 break;
9295
9296 case 4:
9297 //flip v
9298 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9299 draw_sprite_v_flip(destbmp, subBmp, dx, dy);
9300 break;
9301
9302 case 5:
9303 //trans + v flip
9304 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9305 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
9306 break;
9307
9308 case 6:
9309 //pivot + v flip
9310 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9311 pivot_sprite_v_flip(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9312 break;
9313
9314 case 8:
9315 //vlip h
9316 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9317 draw_sprite_h_flip(destbmp, subBmp, dx, dy);
9318 break;
9319
9320 case 9:
9321 //trans + h flip
9322 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9323 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
9324 break;
9325
9326 case 10:
9327 //flip H and pivot
9328 Z_message("Warning: %s cannot both Pivot and H-Flip.\n", funcstr);
9329 //return error cannot pivot and h flip
9330 break;
9331
9332 case 12:
9333 //vh flip
9334 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9335 draw_sprite_vh_flip(destbmp, subBmp, dx, dy);
9336 break;
9337
9338 case 13:
9339 //trans + vh flip
9340 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9341 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
9342 break;
9343
9344 case 14:
9345 //pivot and vh flip
9346 Z_message("Warning: %s cannot both Pivot and VH-Flip.\n", funcstr);
9347 //return error cannot both pivot and vh flip
9348 break;
9349
9350 case 16:
9351 //lit
9352 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9353 draw_lit_sprite(destbmp, subBmp, dx, dy, litcolour);
9354 break;
9355
9356 case 18:
9357 //pivot, lit
9358 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9359 pivot_sprite_lit(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
9360 break;
9361
9362 case 20:
9363 //lit + v flip
9364 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9365 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
9366 break;
9367
9368 case 22:
9369 //Pivot, vflip, lit
9370 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9371 pivot_sprite_v_flip_lit(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
9372 break;
9373
9374 case 24:
9375 //lit + h flip
9376 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9377 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
9378 break;
9379
9380 case 26:
9381 //pivot + lit + hflip
9382 Z_message("Warning: %s cannot both Pivot, Flip, and Lit.\n", funcstr);
9383 //return error cannot pivot, lit, and flip
9384 break;
9385
9386 case 28:
9387 //lit + vh flip
9388 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9389 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
9390 break;
9391
9392 case 32: //gouraud
9393 //Probably not wort supporting.
9394 //masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9395 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
9396 break;
9397
9398 case 0:
9399 //no effect
9400 masked_stretch_blit(srcbmp, destbmp, sx, sy, sw, sh, dx, dy, dw, dh);
9401 break;
9402
9403
9404 default:
9405 return Z_message("Warning: %s mode flags not possible in this combination!\n", funcstr);
9406
9407
9408 }
9409 } //end if not rotated
9410
9411 if ( rot != 0 ) //if rotated
9412 {
9413 switch(mode)
9414 {
9415 case 1:
9416 //transparent
9417 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9418 rotate_sprite_trans(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
9419
9420 break;
9421
9422 case 2:
9423 //pivot?
9424 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9425 pivot_sprite(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9426 //Pivoting requires two more args
9427 break;
9428
9429 case 3:
9430 //pivot + trans
9431 //return an error, cannot both rotate and pivot
9432 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9433 break;
9434
9435 case 4:
9436 //flip v
9437 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9438 rotate_sprite_v_flip(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
9439 break;
9440
9441 case 5:
9442 //trans + v flip
9443 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9444 rotate_sprite_v_flip_trans(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
9445 break;
9446
9447 case 6:
9448 //pivot + v flip
9449 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9450 //return an error, cannot both rotate and pivot
9451 break;
9452
9453 case 8:
9454 //flip h
9455 Z_message("Warning: %s cannot both Rotate and H-Flip.\n", funcstr);
9456 //return an error, cannot both rotate and flip H
9457 break;
9458
9459 case 9:
9460 //trans + h flip
9461 Z_message("Warning: %s cannot Rotate and Flip a Trans Sprite.\n", funcstr);
9462 //return an error, cannot rotate and flip a trans sprite
9463 break;
9464
9465 case 10:
9466 //flip H and pivot
9467 //return error cannot pivot and h flip
9468 Z_message("Warning: %s cannot both Pivot and H-Flip.\n", funcstr);
9469 break;
9470
9471 case 12:
9472 //vh flip
9473 //return an error, cannot rotate and VH flip a trans sprite
9474 Z_message("Warning: %s cannot both Rotate and VH-Flip.\n", funcstr);
9475 break;
9476
9477 case 13:
9478 //trans + vh flip
9479 //return an error, cannot rotate and VH flip a trans sprite
9480 Z_message("Warning: %s cannot both Rotate and VH-Flip.\n", funcstr);
9481 break;
9482
9483 case 14:
9484 //pivot and vh flip
9485 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9486 //return error cannot both pivot and vh flip
9487 break;
9488
9489 case 16:
9490 //lit
9491 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9492 rotate_sprite_lit(destbmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
9493 break;
9494
9495 case 18:
9496 //pivot, lit
9497 //return an error, cannot both rotate and pivot
9498 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9499 break;
9500
9501 case 20:
9502 //lit + vflip
9503 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9504 rotate_sprite_v_flip_lit(destbmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
9505 break;
9506
9507 case 22:
9508 //Pivot, vflip, lit
9509 //return an error, cannot both rotate and pivot
9510 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9511 break;
9512
9513 case 24:
9514 //lit + h flip
9515 //return an error, cannot both rotate and H flip
9516 Z_message("Warning: %s cannot both Rotate and H-Flip.\n", funcstr);
9517 break;
9518
9519 case 26:
9520 //pivot + lit + hflip
9521 Z_message("Warning: %s cannot both Pivot and Flip a Lit Sprite.\n", funcstr);
9522 //return error cannot pivot, lit, and flip
9523 break;
9524
9525 case 28:
9526 //lit + vh flip
9527 //return an error, cannot both rotate and VH flip
9528 Z_message("Warning: %s cannot both Pivot and VH-Flip.\n", funcstr);
9529 break;
9530
9531 case 32: //gouraud
9532 //Probably not wort supporting.
9533 //masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9534 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
9535 break;
9536
9537 case 0:
9538 //no effect.
9539 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9540 rotate_sprite(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
9541 break;
9542
9543 default:
9544 return Z_message("Warning: %s mode flags not possible in this combination!\n", funcstr);
9545
9546 }
9547 }
9548 } //end if stretched and masked
9549
9550 else //stretched, not masked
9551 {
9552
9553
9554 if ( rot == 0 ) //if not rotated
9555 {
9556 switch(mode)
9557 {
9558 case 1:
9559 //transparent
9560 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9561 draw_trans_sprite(destbmp, subBmp, dx, dy);
9562 break;
9563
9564
9565 case 2:
9566 //pivot?
9567 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9568 pivot_sprite(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9569 //Pivoting requires two more args
9570 break;
9571
9572 case 3:
9573 //pivot + trans
9574 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9575 pivot_sprite_trans(destbmp, subBmp, dx,dy, cx, cy, degrees_to_fixed(rot));
9576 break;
9577
9578 case 4:
9579 //flip v
9580 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9581 draw_sprite_v_flip(destbmp, subBmp, dx, dy);
9582 break;
9583
9584 case 5:
9585 //trans + v flip
9586 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9587 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
9588 break;
9589
9590 case 6:
9591 //pivot + v flip
9592 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9593 pivot_sprite_v_flip(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9594 break;
9595
9596 case 8:
9597 //vlip h
9598 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9599 draw_sprite_h_flip(destbmp, subBmp, dx, dy);
9600 break;
9601
9602 case 9:
9603 //trans + h flip
9604 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9605 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
9606 break;
9607
9608 case 10:
9609 //flip H and pivot
9610 Z_message("Warning: %s cannot both Pivot and H-Flip.\n", funcstr);
9611 //return error cannot pivot and h flip
9612 break;
9613
9614 case 12:
9615 //vh flip
9616 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9617 draw_sprite_vh_flip(destbmp, subBmp, dx, dy);
9618 break;
9619
9620 case 13:
9621 //trans + vh flip
9622 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9623 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
9624 break;
9625
9626 case 14:
9627 //pivot and vh flip
9628 Z_message("Warning: %s cannot both Pivot and VH-Flip.\n", funcstr);
9629 //return error cannot both pivot and vh flip
9630 break;
9631
9632 case 16:
9633 //lit
9634 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9635 draw_lit_sprite(destbmp, subBmp, dx, dy, litcolour);
9636 break;
9637
9638 case 18:
9639 //pivot, lit
9640 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9641 pivot_sprite_lit(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
9642 break;
9643
9644 case 20:
9645 //lit + v flip
9646 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9647 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
9648 break;
9649
9650 case 22:
9651 //Pivot, vflip, lit
9652 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9653 pivot_sprite_v_flip_lit(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
9654 break;
9655
9656 case 24:
9657 //lit + h flip
9658 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9659 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
9660 break;
9661
9662 case 26:
9663 //pivot + lit + hflip
9664 Z_message("Warning: %s cannot both Pivot, Flip, and Lit.\n", funcstr);
9665 //return error cannot pivot, lit, and flip
9666 break;
9667
9668 case 28:
9669 //lit + vh flip
9670 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9671 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
9672 break;
9673
9674 case 32: //gouraud
9675 //Probably not wort supporting.
9676 //stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9677 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
9678 break;
9679
9680 case 0:
9681 //no effect
9682 stretch_blit(srcbmp, destbmp, sx, sy, sw, sh, dx, dy, dw, dh);
9683 break;
9684
9685
9686 default:
9687 return Z_message("Warning: %s mode flags not possible in this combination!\n", funcstr);
9688
9689
9690 }
9691 } //end if not rotated
9692
9693 if ( rot != 0 ) //if rotated
9694 {
9695 switch(mode)
9696 {
9697 case 1:
9698 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
9699 rotate_sprite_trans(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
9700
9701 break;
9702
9703 case 2:
9704 //pivot?
9705 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9706 pivot_sprite(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9707 //Pivoting requires two more args
9708 break;
9709
9710 case 3:
9711 //pivot + trans
9712 //return an error, cannot both rotate and pivot
9713 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9714 break;
9715
9716 case 4:
9717 //flip v
9718 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9719 rotate_sprite_v_flip(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
9720 break;
9721
9722 case 5:
9723 //trans + v flip
9724 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9725 rotate_sprite_v_flip_trans(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
9726 break;
9727
9728 case 6:
9729 //pivot + v flip
9730 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9731 //return an error, cannot both rotate and pivot
9732 break;
9733
9734 case 8:
9735 //flip h
9736 Z_message("Warning: %s cannot both Rotate and H-Flip.\n", funcstr);
9737 //return an error, cannot both rotate and flip H
9738 break;
9739
9740 case 9:
9741 //trans + h flip
9742 Z_message("Warning: %s cannot Rotate and Flip a Trans Sprite.\n", funcstr);
9743 //return an error, cannot rotate and flip a trans sprite
9744 break;
9745
9746 case 10:
9747 //flip H and pivot
9748 //return error cannot pivot and h flip
9749 Z_message("Warning: %s cannot both Pivot and H-Flip.\n", funcstr);
9750 break;
9751
9752 case 12:
9753 //vh flip
9754 //return an error, cannot rotate and VH flip a trans sprite
9755 Z_message("Warning: %s cannot both Rotate and VH-Flip.\n", funcstr);
9756 break;
9757
9758 case 13:
9759 //trans + vh flip
9760 //return an error, cannot rotate and VH flip a trans sprite
9761 Z_message("Warning: %s cannot both Rotate and VH-Flip.\n", funcstr);
9762 break;
9763
9764 case 14:
9765 //pivot and vh flip
9766 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9767 //return error cannot both pivot and vh flip
9768 break;
9769
9770 case 16:
9771 //lit
9772 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
9773 rotate_sprite_lit(destbmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
9774 break;
9775
9776 case 18:
9777 //pivot, lit
9778 //return an error, cannot both rotate and pivot
9779 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9780 break;
9781
9782 case 20:
9783 //lit + vflip
9784 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
9785 rotate_sprite_v_flip_lit(destbmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
9786 break;
9787
9788 case 22:
9789 //Pivot, vflip, lit
9790 //return an error, cannot both rotate and pivot
9791 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9792 break;
9793
9794 case 24:
9795 //lit + h flip
9796 //return an error, cannot both rotate and H flip
9797 Z_message("Warning: %s cannot both Rotate and H-Flip.\n", funcstr);
9798 break;
9799
9800 case 26:
9801 //pivot + lit + hflip
9802 Z_message("Warning: %s cannot both Pivot and Flip a Lit Sprite.\n", funcstr);
9803 //return error cannot pivot, lit, and flip
9804 break;
9805
9806 case 28:
9807 //lit + vh flip
9808 //return an error, cannot both rotate and VH flip
9809 Z_message("Warning: %s cannot both Pivot and VH-Flip.\n", funcstr);
9810 break;
9811
9812 case 32: //gouraud
9813 //Probably not wort supporting.
9814 //stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9815 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
9816 break;
9817
9818 case 0:
9819 //no effect.
9820 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9821 rotate_sprite(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
9822 break;
9823
9824 default:
9825 return Z_message("Warning: %s mode flags not possible in this combination!\n", funcstr);
9826
9827 }
9828 }
9829
9830 } //end if stretched, but not masked
9831 }
9832 else //not stretched
9833 {
9834
9835 if(masked) //if masked, but not stretched
9836 {
9837
9838 if ( rot == 0 ) //if not rotated
9839 {
9840 switch(mode)
9841 {
9842 case 1:
9843 //transparent
9844 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9845 draw_trans_sprite(destbmp, subBmp, dx, dy);
9846 break;
9847
9848
9849 case 2:
9850 //pivot?
9851 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9852 pivot_sprite(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9853 //Pivoting requires two more args
9854 break;
9855
9856 case 3:
9857 //pivot + trans
9858 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9859 pivot_sprite_trans(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9860 break;
9861
9862 case 4:
9863 //flip v
9864 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9865 draw_sprite_v_flip(destbmp, subBmp, dx, dy);
9866 break;
9867
9868 case 5:
9869 //trans + v flip
9870 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9871 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
9872 break;
9873
9874 case 6:
9875 //pivot + v flip
9876 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9877 pivot_sprite_v_flip(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9878 break;
9879
9880 case 8:
9881 //vlip h
9882 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9883 draw_sprite_h_flip(destbmp, subBmp, dx, dy);
9884 break;
9885
9886 case 9:
9887 //trans + h flip
9888 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9889 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
9890 break;
9891
9892 case 10:
9893 //flip H and pivot
9894 Z_message("Warning: %s cannot both Pivot and H-Flip.\n", funcstr);
9895 //return error cannot pivot and h flip
9896 break;
9897
9898 case 12:
9899 //vh flip
9900 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9901 draw_sprite_vh_flip(destbmp, subBmp, dx, dy);
9902 break;
9903
9904 case 13:
9905 //trans + vh flip
9906 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9907 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
9908 break;
9909
9910 case 14:
9911 //pivot and vh flip
9912 Z_message("Warning: %s cannot both Pivot and VH-Flip.\n", funcstr);
9913 //return error cannot both pivot and vh flip
9914 break;
9915
9916 case 16:
9917 //lit
9918 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9919 draw_lit_sprite(destbmp, subBmp, dx, dy, litcolour);
9920 break;
9921
9922 case 18:
9923 //pivot, lit
9924 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9925 pivot_sprite_lit(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
9926 break;
9927
9928 case 20:
9929 //lit + v flip
9930 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9931 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
9932 break;
9933
9934 case 22:
9935 //Pivot, vflip, lit
9936 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9937 pivot_sprite_v_flip_lit(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
9938 break;
9939
9940 case 24:
9941 //lit + h flip
9942 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9943 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
9944 break;
9945
9946 case 26:
9947 //pivot + lit + hflip
9948 Z_message("Warning: %s cannot both Pivot, Flip, and Lit.\n", funcstr);
9949 //return error cannot pivot, lit, and flip
9950 break;
9951
9952 case 28:
9953 //lit + vh flip
9954 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9955 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
9956 break;
9957
9958 case 32: //gouraud
9959 //Probably not wort supporting.
9960 //stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9961 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
9962 break;
9963
9964 case 0:
9965 //no effect
9966 masked_blit(srcbmp, destbmp, sx, sy, dx, dy, dw, dh);
9967 break;
9968
9969
9970 default:
9971 return Z_message("Warning: %s mode flags not possible in this combination!\n", funcstr);
9972
9973
9974 }
9975 } //end if not rotated
9976
9977 if ( rot != 0 ) //if rotated
9978 {
9979 switch(mode)
9980 {
9981 case 1:
9982 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh); //transparent
9983 rotate_sprite_trans(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
9984
9985 break;
9986
9987 case 2:
9988 //pivot?
9989 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9990 pivot_sprite(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9991 //Pivoting requires two more args
9992 break;
9993
9994 case 3:
9995 //pivot + trans
9996 //return an error, cannot both rotate and pivot
9997 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9998 break;
9999
10000 case 4:
10001 //flip v
10002 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10003 rotate_sprite_v_flip(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
10004 break;
10005
10006 case 5:
10007 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh); //trans + v flip
10008 rotate_sprite_v_flip_trans(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
10009 break;
10010
10011 case 6:
10012 //pivot + v flip
10013 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
10014 //return an error, cannot both rotate and pivot
10015 break;
10016
10017 case 8:
10018 //flip h
10019 Z_message("Warning: %s cannot both Rotate and H-Flip.\n", funcstr);
10020 //return an error, cannot both rotate and flip H
10021 break;
10022
10023 case 9:
10024 //trans + h flip
10025 Z_message("Warning: %s cannot Rotate and Flip a Trans Sprite.\n", funcstr);
10026 //return an error, cannot rotate and flip a trans sprite
10027 break;
10028
10029 case 10:
10030 //flip H and pivot
10031 //return error cannot pivot and h flip
10032 Z_message("Warning: %s cannot both Pivot and H-Flip.\n", funcstr);
10033 break;
10034
10035 case 12:
10036 //vh flip
10037 //return an error, cannot rotate and VH flip a trans sprite
10038 Z_message("Warning: %s cannot both Rotate and VH-Flip.\n", funcstr);
10039 break;
10040
10041 case 13:
10042 //trans + vh flip
10043 //return an error, cannot rotate and VH flip a trans sprite
10044 Z_message("Warning: %s cannot both Rotate and VH-Flip.\n", funcstr);
10045 break;
10046
10047 case 14:
10048 //pivot and vh flip
10049 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
10050 //return error cannot both pivot and vh flip
10051 break;
10052
10053 case 16:
10054 //lit
10055 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10056 rotate_sprite_lit(destbmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
10057 break;
10058
10059 case 18:
10060 //pivot, lit
10061 //return an error, cannot both rotate and pivot
10062 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
10063 break;
10064
10065 case 20:
10066 //lit + vflip
10067 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10068 rotate_sprite_v_flip_lit(destbmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
10069 break;
10070
10071 case 22:
10072 //Pivot, vflip, lit
10073 //return an error, cannot both rotate and pivot
10074 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
10075 break;
10076
10077 case 24:
10078 //lit + h flip
10079 //return an error, cannot both rotate and H flip
10080 Z_message("Warning: %s cannot both Rotate and H-Flip.\n", funcstr);
10081 break;
10082
10083 case 26:
10084 //pivot + lit + hflip
10085 Z_message("Warning: %s cannot both Pivot and Flip a Lit Sprite.\n", funcstr);
10086 //return error cannot pivot, lit, and flip
10087 break;
10088
10089 case 28:
10090 //lit + vh flip
10091 //return an error, cannot both rotate and VH flip
10092 Z_message("Warning: %s cannot both Pivot and VH-Flip.\n", funcstr);
10093 break;
10094
10095 case 32: //gouraud
10096 //Probably not wort supporting.
10097 //stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
10098 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
10099 break;
10100
10101 case 0:
10102 //no effect.
10103 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10104 rotate_sprite(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
10105 break;
10106
10107 default:
10108 return Z_message("Warning: %s mode flags not possible in this combination!\n", funcstr);
10109
10110 }
10111 } //end rtated, masked
10112 } //end if masked
10113
10114 else //not masked, and not stretched; just blit
10115 {
10116
10117 if ( rot == 0 ) //if not rotated
10118 {
10119 switch(mode)
10120 {
10121 case 1:
10122 //transparent
10123 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10124 draw_trans_sprite(destbmp, subBmp, dx, dy);
10125 break;
10126
10127
10128 case 2:
10129 //pivot?
10130 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10131 pivot_sprite(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
10132 //Pivoting requires two more args
10133 break;
10134
10135 case 3:
10136 //pivot + trans
10137 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10138 pivot_sprite_trans(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
10139 break;
10140
10141 case 4:
10142 //flip v
10143 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10144 draw_sprite_v_flip(destbmp, subBmp, dx, dy);
10145 break;
10146
10147 case 5:
10148 //trans + v flip
10149 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10150 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
10151 break;
10152
10153 case 6:
10154 //pivot + v flip
10155 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10156 pivot_sprite_v_flip(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
10157 break;
10158
10159 case 8:
10160 //vlip h
10161 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10162 draw_sprite_h_flip(destbmp, subBmp, dx, dy);
10163 break;
10164
10165 case 9:
10166 //trans + h flip
10167 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10168 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
10169 break;
10170
10171 case 10:
10172 //flip H and pivot
10173 Z_message("Warning: %s cannot both Pivot and H-Flip.\n", funcstr);
10174 //return error cannot pivot and h flip
10175 break;
10176
10177 case 12:
10178 //vh flip
10179 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10180 draw_sprite_vh_flip(destbmp, subBmp, dx, dy);
10181 break;
10182
10183 case 13:
10184 //trans + vh flip
10185 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10186 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
10187 break;
10188
10189 case 14:
10190 //pivot and vh flip
10191 Z_message("Warning: %s cannot both Pivot and VH-Flip.\n", funcstr);
10192 //return error cannot both pivot and vh flip
10193 break;
10194
10195 case 16:
10196 //lit
10197 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10198 draw_lit_sprite(destbmp, subBmp, dx, dy, litcolour);
10199 break;
10200
10201 case 18:
10202 //pivot, lit
10203 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10204 pivot_sprite_lit(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
10205 break;
10206
10207 case 20:
10208 //lit + v flip
10209 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10210 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
10211 break;
10212
10213 case 22:
10214 //Pivot, vflip, lit
10215 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10216 pivot_sprite_v_flip_lit(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
10217 break;
10218
10219 case 24:
10220 //lit + h flip
10221 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10222 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
10223 break;
10224
10225 case 26:
10226 //pivot + lit + hflip
10227 Z_message("Warning: %s cannot both Pivot, Flip, and Lit.\n", funcstr);
10228 //return error cannot pivot, lit, and flip
10229 break;
10230
10231 case 28:
10232 //lit + vh flip
10233 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10234 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
10235 break;
10236
10237 case 32: //gouraud
10238 //Probably not wort supporting.
10239 //blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10240 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
10241 break;
10242
10243 case 0:
10244 //no effect
10245 blit(srcbmp, destbmp, sx, sy, dx, dy, dw, dh);
10246 break;
10247
10248
10249 default:
10250 return Z_message("Warning: %s mode flags not possible in this combination!\n", funcstr);
10251
10252
10253 }
10254 } //end if not rotated
10255
10256 if ( rot != 0 ) //if rotated
10257 {
10258 switch(mode)
10259 {
10260 case 1:
10261 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);//transparent
10262 rotate_sprite_trans(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
10263
10264 break;
10265
10266 case 2:
10267 //pivot?
10268 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10269 pivot_sprite(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
10270 //Pivoting requires two more args
10271 break;
10272
10273 case 3:
10274 //pivot + trans
10275 //return an error, cannot both rotate and pivot
10276 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
10277 break;
10278
10279 case 4:
10280 //flip v
10281 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10282 rotate_sprite_v_flip(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
10283 break;
10284
10285 case 5:
10286 //trans + v flip
10287 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10288 rotate_sprite_v_flip_trans(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
10289 break;
10290
10291 case 6:
10292 //pivot + v flip
10293 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
10294 //return an error, cannot both rotate and pivot
10295 break;
10296
10297 case 8:
10298 //flip h
10299 Z_message("Warning: %s cannot both Rotate and H-Flip.\n", funcstr);
10300 //return an error, cannot both rotate and flip H
10301 break;
10302
10303 case 9:
10304 //trans + h flip
10305 Z_message("Warning: %s cannot Rotate and Flip a Trans Sprite.\n", funcstr);
10306 //return an error, cannot rotate and flip a trans sprite
10307 break;
10308
10309 case 10:
10310 //flip H and pivot
10311 //return error cannot pivot and h flip
10312 Z_message("Warning: %s cannot both Pivot and H-Flip.\n", funcstr);
10313 break;
10314
10315 case 12:
10316 //vh flip
10317 //return an error, cannot rotate and VH flip a trans sprite
10318 Z_message("Warning: %s cannot both Rotate and VH-Flip.\n", funcstr);
10319 break;
10320
10321 case 13:
10322 //trans + vh flip
10323 //return an error, cannot rotate and VH flip a trans sprite
10324 Z_message("Warning: %s cannot both Rotate and VH-Flip.\n", funcstr);
10325 break;
10326
10327 case 14:
10328 //pivot and vh flip
10329 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
10330 //return error cannot both pivot and vh flip
10331 break;
10332
10333 case 16:
10334 //lit
10335 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10336 rotate_sprite_lit(destbmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
10337 break;
10338
10339 case 18:
10340 //pivot, lit
10341 //return an error, cannot both rotate and pivot
10342 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
10343 break;
10344
10345 case 20:
10346 //lit + vflip
10347 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10348 rotate_sprite_v_flip_lit(destbmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
10349 break;
10350
10351 case 22:
10352 //Pivot, vflip, lit
10353 //return an error, cannot both rotate and pivot
10354 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
10355 break;
10356
10357 case 24:
10358 //lit + h flip
10359 //return an error, cannot both rotate and H flip
10360 Z_message("Warning: %s cannot both Rotate and H-Flip.\n", funcstr);
10361 break;
10362
10363 case 26:
10364 //pivot + lit + hflip
10365 Z_message("Warning: %s cannot both Pivot and Flip a Lit Sprite.\n", funcstr);
10366 //return error cannot pivot, lit, and flip
10367 break;
10368
10369 case 28:
10370 //lit + vh flip
10371 //return an error, cannot both rotate and VH flip
10372 Z_message("Warning: %s cannot both Pivot and VH-Flip.\n", funcstr);
10373 break;
10374
10375 case 32: //gouraud
10376 //Probably not wort supporting.
10377 //blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10378 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
10379 break;
10380
10381 case 0:
10382 //no effect.
10383 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10384 rotate_sprite(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
10385 break;
10386
10387 default:
10388 return Z_message("Warning: %s mode flags not possible in this combination!\n", funcstr);
10389
10390 }
10391 } //end if rotated
10392 } //end if not masked
10393 } //end if not stretched
10394
10395 //cleanup
10396 if(subBmp)
10397 {
10398 //script_drawing_commands.ReleaseSubBitmap(subBmp); //purge the temporary bitmap.
10399 destroy_bitmap(subBmp);
10400 }
10401 destroy_bitmap(srcbmp);
10402 }
10403
10404 void do_comboblit(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool is_bmp)
10405 {
10406 //sdci[2]: combo -> tile
10407 int cid = sdci[2]/10000;
10408 if(unsigned(cid) >= MAXCOMBOS)
10409 {
10410 Z_scripterrlog("ComboBlit tried to draw invalid combo id '%d'\n", cid);
10411 return;
10412 }
10413 sdci[2] = GET_DRAWING_COMBO(cid).tile * 10000;
10414 do_tileblit(bmp, sdci, xoffset, yoffset, is_bmp, "ComboBlit()");
10415 }
10416
10417 void bmp_do_drawquad3dr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
10418 {
10419
10420 //sdci[1]=layer
10421 //sdci[2]=pos[12]
10422 //sdci[3]=uv[8]
10423 //sdci[4]=color[4]
10424 //sdci[5]=size[2]
10425 //sdci[6]=flip
10426 //sdci[7]=tile/combo
10427 //sdci[8]=polytype
10428 //sdci[9] = other bitmap as texture
10429 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
10430 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
10431 {
10432 Z_scripterrlog("bitmap->Quad3D() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
10433 return;
10434 }
10435 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
10436 if ( refbmp == NULL ) return;
10437
10438 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
10439
10440 if(!v_ptr)
10441 {
10442 al_trace("Quad3d: Vector pointer is null! Internal error. \n");
10443 return;
10444 }
10445
10446 std::vector<int32_t> &v = *v_ptr;
10447
10448 if(v.empty())
10449 return;
10450
10451 int32_t* pos = &v[0];
10452 int32_t* uv = &v[12];
10453 int32_t* col = &v[20];
10454 int32_t* size = &v[24];
10455
10456 int32_t w = size[0]; //magic numerical constants... yuck.
10457 int32_t h = size[1];
10458 int32_t flip = (sdci[6]/10000)&3;
10459 int32_t tile = sdci[7]/10000;
10460 int32_t polytype = sdci[8]/10000;
10461 int32_t quad_render_source = sdci[9];
10462 Z_scripterrlog("Quad3D texture is %d\n", quad_render_source);
10463
10464 polytype = vbound(polytype, 0, 14);
10465
10466 int32_t tex_width = w*16;
10467 int32_t tex_height = h*16;
10468
10469 bool mustDestroyBmp = false;
10470 BITMAP *tex=NULL;
10471
10472
10473 bool tex_is_bitmap = ( sdci[9] != 0 );
10474 //Z_scripterrlog("sdci[9] is %d\n", quad_render_source);
10475 //Z_scripterrlog("sdci[DRAWCMD_BMP_TARGET] is %d\n", sdci[DRAWCMD_BMP_TARGET]);
10476 BITMAP *bmptexture;
10477
10478 if ( tex_is_bitmap ) bmptexture = FFCore.GetScriptBitmap(quad_render_source);
10479
10480 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
10481
10482
10483 if ( !tex_is_bitmap )
10484 {
10485 tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
10486
10487 if(!tex)
10488 {
10489 mustDestroyBmp = true;
10490 tex = create_bitmap_ex(8, tex_width, tex_height);
10491 clear_bitmap(tex);
10492 }
10493 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
10494 {
10495 Z_message("Quad3d() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
10496 return; //non power of two error
10497 }
10498 if(tile > 0) // TILE
10499 {
10500 TileHelper::OverTile(tex, tile, 0, 0, w, h, col[0], flip);
10501 }
10502 else // COMBO
10503 {
10504 auto& c = GET_DRAWING_COMBO(vbound(abs(tile), 0, 0xffff));
10505 const int32_t tiletodraw = combo_tile(c, 0, 0);
10506 flip = flip ^ c.flip;
10507
10508 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, col[0], flip);
10509 }
10510
10511 V3D_f V1 = { static_cast<float>(pos[0]+xoffset), static_cast<float>(pos[1] +yoffset), static_cast<float>(pos[2]), static_cast<float>(uv[0]), static_cast<float>(uv[1]), col[0] };
10512 V3D_f V2 = { static_cast<float>(pos[3]+xoffset), static_cast<float>(pos[4] +yoffset), static_cast<float>(pos[5]), static_cast<float>(uv[2]), static_cast<float>(uv[3]), col[1] };
10513 V3D_f V3 = { static_cast<float>(pos[6]+xoffset), static_cast<float>(pos[7] +yoffset), static_cast<float>(pos[8]), static_cast<float>(uv[4]), static_cast<float>(uv[5]), col[2] };
10514 V3D_f V4 = { static_cast<float>(pos[9]+xoffset), static_cast<float>(pos[10]+yoffset), static_cast<float>(pos[11]), static_cast<float>(uv[6]), static_cast<float>(uv[7]), col[3] };
10515
10516 quad3d_f(refbmp, polytype, tex, &V1, &V2, &V3, &V4);
10517 if(mustDestroyBmp)
10518 destroy_bitmap(tex);
10519 }
10520 else
10521 {
10522
10523 if ( !bmptexture )
10524 {
10525 Z_scripterrlog("Bitmap pointer used as a texture in %s is uninitialised.\n Defaulting to using a tile as a texture.\n", "bitmap->Quad3D()");
10526 tex_is_bitmap = 0;
10527 return;
10528 }
10529 if ( !isPowerOfTwo(bmptexture->h) ) Z_scripterrlog("HEIGHT of Bitmap ( pointer %d ) provided as a render source for bitmap->Quad3D is not a POWER OF TWO.\nTextels may render improperly!\n", quad_render_source);
10530 if ( !isPowerOfTwo(bmptexture->w) ) Z_scripterrlog("WIDTH of Bitmap ( pointer %d ) provided as a render source for bitmap->Quad3D is not a POWER OF TWO.\nTextels may render improperly!\n", quad_render_source);
10531 if ( !isPowerOfTwo(h) ) Z_scripterrlog("WIDTH ARG (%d) provided as a render source for bitmap->Quad3D is not a POWER OF TWO.\nTextels may render improperly!\n", h);
10532 if ( !isPowerOfTwo(w) ) Z_scripterrlog("HEIGHT ARG (%d) provided as a render source for bitmap->Quad3D is not a POWER OF TWO.\nTextels may render improperly!\n", w);
10533
10534 V3D_f V1 = { static_cast<float>(pos[0]+xoffset), static_cast<float>(pos[1] +yoffset), static_cast<float>(pos[2]), static_cast<float>(uv[0]), static_cast<float>(uv[1]), col[0] };
10535 V3D_f V2 = { static_cast<float>(pos[3]+xoffset), static_cast<float>(pos[4] +yoffset), static_cast<float>(pos[5]), static_cast<float>(uv[2]), static_cast<float>(uv[3]), col[1] };
10536 V3D_f V3 = { static_cast<float>(pos[6]+xoffset), static_cast<float>(pos[7] +yoffset), static_cast<float>(pos[8]), static_cast<float>(uv[4]), static_cast<float>(uv[5]), col[2] };
10537 V3D_f V4 = { static_cast<float>(pos[9]+xoffset), static_cast<float>(pos[10]+yoffset), static_cast<float>(pos[11]), static_cast<float>(uv[6]), static_cast<float>(uv[7]), col[3] };
10538
10539 BITMAP *foo = create_bitmap_ex(8, 256, 176);
10540
10541 //quad3d_f(refbmp, polytype, foo, &V1, &V2, &V3, &V4);
10542 quad3d_f(refbmp, polytype, bmptexture, &V1, &V2, &V3, &V4);
10543 destroy_bitmap(foo);
10544
10545 }
10546
10547
10548
10549 }
10550
10551
10552
10553 void bmp_do_drawtriangle3dr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
10554 {
10555 //sdci[1]=layer
10556 //sdci[2]=pos[9]
10557 //sdci[3]=uv[6]
10558 //sdci[4]=color[3]
10559 //sdci[5]=size[2]
10560 //sdci[6]=flip
10561 //sdci[7]=tile/combo
10562 //sdci[8]=polytype
10563 //sdci[9] bitmap as texture
10564 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
10565 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
10566 {
10567 Z_scripterrlog("bitmap->Triangle3D() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
10568 return;
10569 }
10570 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
10571 if ( refbmp == NULL ) return;
10572
10573 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
10574
10575 if(!v_ptr)
10576 {
10577 al_trace("bitmap->Triangle3d: Vector pointer is null! Internal error. \n");
10578 return;
10579 }
10580
10581 std::vector<int32_t> &v = *v_ptr;
10582
10583 if(v.empty())
10584 return;
10585
10586 int32_t* pos = &v[0];
10587 int32_t* uv = &v[9];
10588 int32_t* col = &v[15];
10589 int32_t* size = &v[18];
10590
10591 int32_t w = size[0]; //magic numerical constants... yuck.
10592 int32_t h = size[1];
10593 int32_t flip = (sdci[6]/10000)&3;
10594 int32_t tile = sdci[7]/10000;
10595 int32_t polytype = sdci[8]/10000;
10596 int32_t quad_render_source = sdci[9];
10597 polytype = vbound(polytype, 0, 14);
10598
10599 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
10600 {
10601 Z_message("bitmap->Triangle3d() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
10602 return; //non power of two error
10603 }
10604
10605 int32_t tex_width = w*16;
10606 int32_t tex_height = h*16;
10607
10608 bool mustDestroyBmp = false;
10609 BITMAP *tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
10610
10611 if(!tex)
10612 {
10613 mustDestroyBmp = true;
10614 tex = create_bitmap_ex(8, tex_width, tex_height);
10615 clear_bitmap(tex);
10616 }
10617
10618 bool tex_is_bitmap = ( sdci[9] != 0 );
10619 BITMAP *bmptexture=NULL;
10620 if ( tex_is_bitmap )
10621 {
10622 bmptexture = FFCore.GetScriptBitmap(quad_render_source);
10623 if ( !bmptexture )
10624 {
10625 Z_scripterrlog("Bitmap pointer used as a texture in %s is uninitialised.\n Defaulting to using a tile as a texture.\n", "bitmap->Triangle3()");
10626 tex_is_bitmap = 0;
10627 }
10628 }
10629
10630 if ( !tex_is_bitmap )
10631 {
10632 if(tile > 0) // TILE
10633 {
10634 TileHelper::OverTile(tex, tile, 0, 0, w, h, col[0], flip);
10635 }
10636 else // COMBO
10637 {
10638 auto& c = GET_DRAWING_COMBO(vbound(abs(tile), 0, 0xffff));
10639 const int32_t tiletodraw = combo_tile(c, 0, 0);
10640 flip = flip ^ c.flip;
10641
10642 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, col[0], flip);
10643 }
10644
10645 V3D_f V1 = { static_cast<float>(pos[0]+xoffset), static_cast<float>(pos[1] +yoffset), static_cast<float>(pos[2]), static_cast<float>(uv[0]), static_cast<float>(uv[1]), col[0] };
10646 V3D_f V2 = { static_cast<float>(pos[3]+xoffset), static_cast<float>(pos[4] +yoffset), static_cast<float>(pos[5]), static_cast<float>(uv[2]), static_cast<float>(uv[3]), col[1] };
10647 V3D_f V3 = { static_cast<float>(pos[6]+xoffset), static_cast<float>(pos[7] +yoffset), static_cast<float>(pos[8]), static_cast<float>(uv[4]), static_cast<float>(uv[5]), col[2] };
10648
10649 triangle3d_f(refbmp, polytype, tex, &V1, &V2, &V3);
10650 }
10651 else
10652 {
10653 if ( !isPowerOfTwo(bmptexture->h) ) Z_scripterrlog("HEIGHT of Bitmap ( pointer %d ) provided as a render source for bitmap->Triangle3D is not a POWER OF TWO.\nTextels may render improperly!\n", quad_render_source);
10654 if ( !isPowerOfTwo(bmptexture->w) ) Z_scripterrlog("WIDTH of Bitmap ( pointer %d ) provided as a render source for bitmap->Triangle3D is not a POWER OF TWO.\nTextels may render improperly!\n", quad_render_source);
10655 if ( !isPowerOfTwo(w) ) Z_scripterrlog("WIDTH ARG (%d) provided as a render source for bitmap->Triangle3D is not a POWER OF TWO.\nTextels may render improperly!\n", w);
10656 if ( !isPowerOfTwo(h) ) Z_scripterrlog("HEIGHT ARG (%d) provided as a render source for bitmap->Triangle3D is not a POWER OF TWO.\nTextels may render improperly!\n", h);
10657
10658 V3D_f V1 = { static_cast<float>(pos[0]+xoffset), static_cast<float>(pos[1] +yoffset), static_cast<float>(pos[2]), static_cast<float>(uv[0]), static_cast<float>(uv[1]), col[0] };
10659 V3D_f V2 = { static_cast<float>(pos[3]+xoffset), static_cast<float>(pos[4] +yoffset), static_cast<float>(pos[5]), static_cast<float>(uv[2]), static_cast<float>(uv[3]), col[1] };
10660 V3D_f V3 = { static_cast<float>(pos[6]+xoffset), static_cast<float>(pos[7] +yoffset), static_cast<float>(pos[8]), static_cast<float>(uv[4]), static_cast<float>(uv[5]), col[2] };
10661
10662 triangle3d_f(refbmp, polytype, bmptexture, &V1, &V2, &V3);
10663
10664
10665 }
10666 if(mustDestroyBmp)
10667 destroy_bitmap(tex);
10668
10669 }
10670
10671
10672 bool is_layer_transparent(const mapscr& m, int32_t layer)
10673 {
10674 layer = vbound(layer, 0, 5);
10675 return m.layeropacity[layer] == 128;
10676 }
10677
10678 4338133 mapscr *getmapscreen(int32_t map_index, int32_t screen, int32_t layer) //returns NULL for invalid or non-existent layer
10679 {
10680 mapscr *base_scr;
10681 4338133 int32_t index = map_index*MAPSCRS+screen;
10682
10683
2/4
✓ Branch 0 taken 4338133 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4338133 times.
4338133 if((uint32_t)layer > 6 || (uint32_t)index >= TheMaps.size())
10684 return NULL;
10685
10686
2/2
✓ Branch 0 taken 3553227 times.
✓ Branch 1 taken 784906 times.
4338133 if(layer != 0)
10687 {
10688 784906 layer = layer - 1;
10689
10690 784906 base_scr=&(TheMaps[index]);
10691
10692
2/2
✓ Branch 0 taken 748179 times.
✓ Branch 1 taken 36727 times.
784906 if(base_scr->layermap[layer]==0)
10693 36727 return NULL;
10694
10695 748179 index=(base_scr->layermap[layer]-1)*MAPSCRS+base_scr->layerscreen[layer];
10696
10697
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 748179 times.
748179 if((uint32_t)index >= TheMaps.size()) // Might as well make sure
10698 return NULL;
10699 748179 }
10700
10701 4301406 return &(TheMaps[index]);
10702 4338133 }
10703
10704 191560 void draw_mapscr(BITMAP *b, const mapscr& m, int32_t x, int32_t y, bool transparent)
10705 {
10706
2/2
✓ Branch 0 taken 33714560 times.
✓ Branch 1 taken 191560 times.
33906120 for(int32_t i(0); i < 176; ++i)
10707 {
10708 33714560 const int32_t x2 = ((i&15)<<4) + x;
10709 33714560 const int32_t y2 = (i&0xF0) + y;
10710
10711
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 33714560 times.
33714560 if(transparent)
10712 {
10713 overcomboblocktranslucent(b, x2, y2, m.data[i], m.cset[i], 1, 1, 128);
10714 }
10715 else
10716 {
10717 33714560 overcomboblock(b, x2, y2, m.data[i], m.cset[i], 1, 1);
10718 }
10719 33714560 }
10720 191560 }
10721
10722 void draw_map_solidity(BITMAP *b, const mapscr& m, int32_t x, int32_t y)
10723 {
10724 BITMAP* square = create_bitmap_ex(8,16,16);
10725
10726 for(int32_t i(0); i < 176; ++i)
10727 {
10728 const int32_t x2 = ((i&15)<<4) + x;
10729 const int32_t y2 = (i&0xF0) + y;
10730 //Blit the palette index of the solidity value.
10731 clear_to_color(square,(combobuf[m.data[i]].walk&15));
10732 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS)) blit(square, b, 0, 0, x2, y2, square->w, square->h);
10733 else masked_blit(square, b, 0, 0, x2, y2, square->w, square->h);
10734 }
10735 destroy_bitmap(square);
10736 }
10737
10738 void do_bmpdrawscreen_solidmaskr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
10739 {
10740 //sdci[1]=layer
10741 //sdci[2]=map
10742 //sdci[3]=screen
10743 //sdci[4]=x
10744 //sdci[5]=y
10745 //sdci[6]=rotation
10746 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
10747
10748 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
10749 if ( refbmp == NULL ) return;
10750
10751 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
10752
10753 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
10754 int32_t screen = sdci[3]/10000;
10755 int32_t x = sdci[4]/10000;
10756 int32_t y = sdci[5]/10000;
10757 int32_t x1 = x + xoffset;
10758 int32_t y1 = y + yoffset;
10759 int32_t rotation = sdci[6]/10000;
10760 uint32_t index = (uint32_t)map_screen_index(map, screen);
10761
10762 if(index >= TheMaps.size())
10763 {
10764 al_trace("DrawScreen: invalid map or screen index. \n");
10765 return;
10766 }
10767
10768 const mapscr & m = TheMaps[index];
10769
10770
10771 BITMAP* b = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
10772 if ( refbmp == NULL ) return;
10773
10774 if(rotation != 0)
10775 b = script_drawing_commands.AquireSubBitmap(256, 176);
10776
10777 //draw layer 0
10778 draw_map_solidity(b, m, x1, y1);
10779 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS))
10780 {
10781 for(int32_t i(0); i < 6; ++i)
10782 {
10783 if(m.layermap[i] == 0) continue;
10784
10785 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
10786
10787 if(layer_screen_index >= TheMaps.size())
10788 continue;
10789
10790 //draw valid layers
10791 draw_map_solidity(b, TheMaps[ layer_screen_index ], x1, y1);
10792 }
10793 }
10794
10795 if(rotation != 0) // rotate
10796 {
10797 rotate_sprite(refbmp, b, x1, y1, degrees_to_fixed(rotation));
10798 script_drawing_commands.ReleaseSubBitmap(b);
10799 }
10800 }
10801
10802 void draw_map_solid(BITMAP *b, const mapscr& m, int32_t x, int32_t y)
10803 {
10804 BITMAP* square = create_bitmap_ex(8,16,16);
10805 BITMAP* subsquare = create_bitmap_ex(8,16,16);
10806 clear_to_color(subsquare,1);
10807
10808 for(int32_t i(0); i < 176; ++i)
10809 {
10810 const int32_t x2 = ((i&15)<<4) + x;
10811 const int32_t y2 = (i&0xF0) + y;
10812 //Blit the palette index of the solidity value.
10813 clear_bitmap(square);
10814 int32_t sol = (combobuf[m.data[i]].walk);
10815 if ( sol & 1 )
10816 {
10817 blit(subsquare, square, 0, 0, 0, 0, 8, 8);
10818 }
10819 if ( sol & 2 )
10820 {
10821 blit(subsquare, square, 0, 0, 0, 8, 8, 8);
10822 }
10823 if ( sol & 4 )
10824 {
10825 blit(subsquare, square, 0, 0, 8, 0, 8, 8);
10826 }
10827 if ( sol &8 ) {
10828 blit(subsquare, square, 0, 0, 8, 8, 8, 8);
10829 }
10830
10831 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS)) blit(square, b, 0, 0, x2, y2, square->w, square->h);
10832 else masked_blit(square, b, 0, 0, x2, y2, square->w, square->h);
10833 }
10834 destroy_bitmap(square);
10835 destroy_bitmap(subsquare);
10836 }
10837
10838 void do_bmpdrawscreen_solidr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
10839 {
10840 //sdci[1]=layer
10841 //sdci[2]=map
10842 //sdci[3]=screen
10843 //sdci[4]=x
10844 //sdci[5]=y
10845 //sdci[6]=rotation
10846 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
10847
10848 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
10849 if ( refbmp == NULL ) return;
10850
10851 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
10852
10853 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
10854 int32_t screen = sdci[3]/10000;
10855 int32_t x = sdci[4]/10000;
10856 int32_t y = sdci[5]/10000;
10857 int32_t x1 = x + xoffset;
10858 int32_t y1 = y + yoffset;
10859 int32_t rotation = sdci[6]/10000;
10860
10861 uint32_t index = (uint32_t)map_screen_index(map, screen);
10862
10863 if(index >= TheMaps.size())
10864 {
10865 al_trace("DrawScreen: invalid map or screen index. \n");
10866 return;
10867 }
10868
10869 const mapscr & m = TheMaps[index];
10870
10871
10872 BITMAP* b = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
10873 if ( refbmp == NULL ) return;
10874
10875 if(rotation != 0)
10876 b = script_drawing_commands.AquireSubBitmap(256, 176);
10877
10878 //draw layer 0
10879 draw_map_solid(b, m, x1, y1);
10880
10881 for(int32_t i(0); i < 6; ++i) //This one doesn't need the QR; it works just fine.
10882 {
10883 if(m.layermap[i] == 0) continue;
10884
10885 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
10886
10887 if(layer_screen_index >= TheMaps.size())
10888 continue;
10889
10890 //draw valid layers
10891 draw_map_solid(b, TheMaps[ layer_screen_index ], x1, y1);
10892 }
10893
10894 if(rotation != 0) // rotate
10895 {
10896 rotate_sprite(refbmp, b, x1, y1, degrees_to_fixed(rotation));
10897 script_drawing_commands.ReleaseSubBitmap(b);
10898 }
10899 }
10900
10901 1024 void draw_map_cflag(BITMAP *b, const mapscr& m, int32_t x, int32_t y)
10902 {
10903 1024 BITMAP* square = create_bitmap_ex(8,16,16);
10904
10905
2/2
✓ Branch 0 taken 180224 times.
✓ Branch 1 taken 1024 times.
181248 for(int32_t i(0); i < 176; ++i)
10906 {
10907 180224 const int32_t x2 = ((i&15)<<4) + x;
10908 180224 const int32_t y2 = (i&0xF0) + y;
10909 //Blit the palette index of the solidity value.
10910 180224 clear_to_color(square,m.sflag[i]);
10911
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 180224 times.
180224 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS)) blit(square, b, 0, 0, x2, y2, square->w, square->h);
10912 180224 else masked_blit(square, b, 0, 0, x2, y2, square->w, square->h);
10913 180224 }
10914 1024 destroy_bitmap(square);
10915 1024 }
10916
10917 1024 void do_bmpdrawscreen_cflagr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
10918 {
10919 //sdci[1]=layer
10920 //sdci[2]=map
10921 //sdci[3]=screen
10922 //sdci[4]=x
10923 //sdci[5]=y
10924 //sdci[6]=rotation
10925 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
10926
10927 1024 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
10928
1/2
✓ Branch 0 taken 1024 times.
✗ Branch 1 not taken.
1024 if ( refbmp == NULL ) return;
10929
10930
2/4
✓ Branch 0 taken 1024 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1024 times.
✗ Branch 3 not taken.
1024 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
10931
10932 1024 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
10933 1024 int32_t screen = sdci[3]/10000;
10934 1024 int32_t x = sdci[4]/10000;
10935 1024 int32_t y = sdci[5]/10000;
10936 1024 int32_t x1 = x + xoffset;
10937 1024 int32_t y1 = y + yoffset;
10938 1024 int32_t rotation = sdci[6]/10000;
10939
10940 1024 uint32_t index = (uint32_t)map_screen_index(map, screen);
10941
10942
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1024 times.
1024 if(index >= TheMaps.size())
10943 {
10944 al_trace("DrawScreen: invalid map or screen index. \n");
10945 return;
10946 }
10947
10948 1024 const mapscr & m = TheMaps[index];
10949
10950
10951 1024 BITMAP* b = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
10952
1/2
✓ Branch 0 taken 1024 times.
✗ Branch 1 not taken.
1024 if ( refbmp == NULL ) return;
10953
10954
1/2
✓ Branch 0 taken 1024 times.
✗ Branch 1 not taken.
1024 if(rotation != 0)
10955 b = script_drawing_commands.AquireSubBitmap(256, 176);
10956
10957 //draw layer 0
10958 1024 draw_map_cflag(b, m, x1, y1);
10959
1/2
✓ Branch 0 taken 1024 times.
✗ Branch 1 not taken.
1024 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS))
10960 {
10961 for(int32_t i(0); i < 6; ++i)
10962 {
10963 if(m.layermap[i] == 0) continue;
10964
10965 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
10966
10967 if(layer_screen_index >= TheMaps.size())
10968 continue;
10969
10970 //draw valid layers
10971 draw_map_cflag(b, TheMaps[ layer_screen_index ], x1, y1);
10972 }
10973 }
10974
10975
1/2
✓ Branch 0 taken 1024 times.
✗ Branch 1 not taken.
1024 if(rotation != 0) // rotate
10976 {
10977 rotate_sprite(refbmp, b, x1, y1, degrees_to_fixed(rotation));
10978 script_drawing_commands.ReleaseSubBitmap(b);
10979 }
10980 1024 }
10981
10982
10983 void draw_map_combotype(BITMAP *b, const mapscr& m, int32_t x, int32_t y)
10984 {
10985 BITMAP* square = create_bitmap_ex(8,16,16);
10986
10987 for(int32_t i(0); i < 176; ++i)
10988 {
10989 const int32_t x2 = ((i&15)<<4) + x;
10990 const int32_t y2 = (i&0xF0) + y;
10991 //Blit the palette index of the solidity value.
10992 clear_to_color(square,(combobuf[m.data[i]].type));
10993 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS)) blit(square, b, 0, 0, x2, y2, square->w, square->h);
10994 else masked_blit(square, b, 0, 0, x2, y2, square->w, square->h);
10995 }
10996 destroy_bitmap(square);
10997 }
10998
10999 void do_bmpdrawscreen_ctyper(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11000 {
11001 //sdci[1]=layer
11002 //sdci[2]=map
11003 //sdci[3]=screen
11004 //sdci[4]=x
11005 //sdci[5]=y
11006 //sdci[6]=rotation
11007 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
11008
11009 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
11010 if ( refbmp == NULL ) return;
11011
11012 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
11013
11014 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11015 int32_t screen = sdci[3]/10000;
11016 int32_t x = sdci[4]/10000;
11017 int32_t y = sdci[5]/10000;
11018 int32_t x1 = x + xoffset;
11019 int32_t y1 = y + yoffset;
11020 int32_t rotation = sdci[6]/10000;
11021
11022 uint32_t index = (uint32_t)map_screen_index(map, screen);
11023
11024 if(index >= TheMaps.size())
11025 {
11026 al_trace("DrawScreen: invalid map or screen index. \n");
11027 return;
11028 }
11029
11030 const mapscr & m = TheMaps[index];
11031
11032
11033 BITMAP* b = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
11034 if ( refbmp == NULL ) return;
11035
11036 if(rotation != 0)
11037 b = script_drawing_commands.AquireSubBitmap(256, 176);
11038
11039 //draw layer 0
11040 draw_map_combotype(b, m, x1, y1);
11041
11042 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS))
11043 {
11044 for(int32_t i(0); i < 6; ++i)
11045 {
11046 if(m.layermap[i] == 0) continue;
11047
11048 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
11049
11050 if(layer_screen_index >= TheMaps.size())
11051 continue;
11052
11053 //draw valid layers
11054 draw_map_combotype(b, TheMaps[ layer_screen_index ], x1, y1);
11055 }
11056 }
11057
11058 if(rotation != 0) // rotate
11059 {
11060 rotate_sprite(refbmp, b, x1, y1, degrees_to_fixed(rotation));
11061 script_drawing_commands.ReleaseSubBitmap(b);
11062 }
11063 }
11064
11065
11066 void draw_map_comboiflag(BITMAP *b, const mapscr& m, int32_t x, int32_t y)
11067 {
11068 BITMAP* square = create_bitmap_ex(8,16,16);
11069
11070 for(int32_t i(0); i < 176; ++i)
11071 {
11072 const int32_t x2 = ((i&15)<<4) + x;
11073 const int32_t y2 = (i&0xF0) + y;
11074 //Blit the palette index of the solidity value.
11075 clear_to_color(square,(combobuf[m.data[i]].flag));
11076 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS)) blit(square, b, 0, 0, x2, y2, square->w, square->h);
11077 else masked_blit(square, b, 0, 0, x2, y2, square->w, square->h);
11078 }
11079 destroy_bitmap(square);
11080 }
11081
11082 void do_bmpdrawscreen_ciflagr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11083 {
11084 //sdci[1]=layer
11085 //sdci[2]=map
11086 //sdci[3]=screen
11087 //sdci[4]=x
11088 //sdci[5]=y
11089 //sdci[6]=rotation
11090 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
11091
11092 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
11093 if ( refbmp == NULL ) return;
11094
11095 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
11096
11097 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11098 int32_t screen = sdci[3]/10000;
11099 int32_t x = sdci[4]/10000;
11100 int32_t y = sdci[5]/10000;
11101 int32_t x1 = x + xoffset;
11102 int32_t y1 = y + yoffset;
11103 int32_t rotation = sdci[6]/10000;
11104
11105 uint32_t index = (uint32_t)map_screen_index(map, screen);
11106
11107 if(index >= TheMaps.size())
11108 {
11109 al_trace("DrawScreen: invalid map or screen index. \n");
11110 return;
11111 }
11112
11113 const mapscr & m = TheMaps[index];
11114
11115
11116 BITMAP* b = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
11117 if ( refbmp == NULL ) return;
11118
11119 if(rotation != 0)
11120 b = script_drawing_commands.AquireSubBitmap(256, 176);
11121
11122 //draw layer 0
11123 draw_map_comboiflag(b, m, x1, y1);
11124
11125 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS))
11126 {
11127 for(int32_t i(0); i < 6; ++i)
11128 {
11129 if(m.layermap[i] == 0) continue;
11130
11131 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
11132
11133 if(layer_screen_index >= TheMaps.size())
11134 continue;
11135
11136 //draw valid layers
11137 draw_map_comboiflag(b, TheMaps[ layer_screen_index ], x1, y1);
11138 }
11139 }
11140
11141 if(rotation != 0) // rotate
11142 {
11143 rotate_sprite(refbmp, b, x1, y1, degrees_to_fixed(rotation));
11144 script_drawing_commands.ReleaseSubBitmap(b);
11145 }
11146 }
11147
11148 4336960 void do_drawlayerr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11149 {
11150 //sdci[1]=layer
11151 //sdci[2]=map
11152 //sdci[3]=screen
11153 //sdci[4]=layer
11154 //sdci[5]=x
11155 //sdci[6]=y
11156 //sdci[7]=rotation
11157 //sdci[8]=opacity
11158
11159 4336960 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11160 4336960 int32_t screen = sdci[3]/10000;
11161 4336960 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
11162 4336960 int32_t x = sdci[5]/10000;
11163 4336960 int32_t y = sdci[6]/10000;
11164 4336960 int32_t x1 = x + xoffset;
11165 4336960 int32_t y1 = y + yoffset;
11166 4336960 int32_t rotation = sdci[7]/10000;
11167 4336960 int32_t opacity = sdci[8]/10000;
11168
11169 4336960 uint32_t index = (uint32_t)map_screen_index(map, screen);
11170 4336960 const mapscr* m = getmapscreen(map, screen, sourceLayer);
11171
11172
2/2
✓ Branch 0 taken 4300239 times.
✓ Branch 1 taken 36721 times.
4336960 if(!m) //no need to log it.
11173 36721 return;
11174
11175
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4300239 times.
4300239 if(index >= TheMaps.size())
11176 {
11177 al_trace("DrawLayer: invalid map index \"%i\". Map count is %lu.\n", index, TheMaps.size());
11178 return;
11179 }
11180
11181 4300239 const mapscr & l = *m;
11182
11183 4300239 BITMAP* b = bmp;
11184
11185
1/2
✓ Branch 0 taken 4300239 times.
✗ Branch 1 not taken.
4300239 if(rotation != 0)
11186 b = script_drawing_commands.AquireSubBitmap(256, 176);
11187
11188
11189 4300239 const int32_t maxX = isOffScreen ? 512 : 256;
11190
2/2
✓ Branch 0 taken 4280939 times.
✓ Branch 1 taken 19300 times.
4300239 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
11191 4300239 bool transparent = opacity <= 128;
11192
11193
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4300239 times.
4300239 if(rotation != 0) // rotate
11194 {
11195 draw_mapscr(b, l, x1, y1, transparent);
11196
11197 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
11198 script_drawing_commands.ReleaseSubBitmap(b);
11199 }
11200 else
11201 {
11202
2/2
✓ Branch 0 taken 756842064 times.
✓ Branch 1 taken 4300239 times.
761142303 for(int32_t i(0); i < 176; ++i)
11203 {
11204 756842064 const int32_t x2 = ((i&15)<<4) + x1;
11205 756842064 const int32_t y2 = (i&0xF0) + y1;
11206
11207
7/8
✓ Branch 0 taken 666337430 times.
✓ Branch 1 taken 90504634 times.
✓ Branch 2 taken 666337430 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 611932038 times.
✓ Branch 5 taken 54405392 times.
✓ Branch 6 taken 9155742 times.
✓ Branch 7 taken 602776296 times.
756842064 if(x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY) //in clipping rect
11208 {
11209
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 602776296 times.
602776296 if(opacity < 128)
11210 {
11211 overcomboblocktranslucent(b, x2, y2, l.data[i], l.cset[i], 1, 1, 128);
11212
11213
11214 //overtiletranslucent16(b, tile, x2, y2, l.cset[i], c.flip, opacity);
11215 }
11216 else
11217 {
11218 602776296 overcomboblock(b, x2, y2, l.data[i], l.cset[i], 1, 1);
11219 //overtile16(b, tile, x2, y2, l.cset[i], c.flip);
11220 }
11221 //putcombo( b, xx, yy, l.data[i], l.cset[i] );
11222 602776296 }
11223 756842064 }
11224 }
11225
11226 //putscr
11227 4336960 }
11228
11229
11230
11231 50406 void do_drawscreenr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11232 {
11233 //sdci[1]=layer
11234 //sdci[2]=map
11235 //sdci[3]=screen
11236 //sdci[4]=x
11237 //sdci[5]=y
11238 //sdci[6]=rotation
11239
11240 50406 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11241 50406 int32_t screen = sdci[3]/10000;
11242 50406 int32_t x = sdci[4]/10000;
11243 50406 int32_t y = sdci[5]/10000;
11244 50406 int32_t x1 = x + xoffset;
11245 50406 int32_t y1 = y + yoffset;
11246 50406 int32_t rotation = sdci[6]/10000;
11247
11248 50406 uint32_t index = (uint32_t)map_screen_index(map, screen);
11249
11250
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50406 times.
50406 if(index >= TheMaps.size())
11251 {
11252 al_trace("DrawScreen: invalid map or screen index. \n");
11253 return;
11254 }
11255
11256 50406 const mapscr & m = TheMaps[index];
11257
11258
11259 50406 BITMAP* b = bmp;
11260
11261
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50406 times.
50406 if(rotation != 0)
11262 b = script_drawing_commands.AquireSubBitmap(256, 176);
11263
11264 //draw layer 0
11265 50406 draw_mapscr(b, m, x1, y1, false);
11266
11267
2/2
✓ Branch 0 taken 50406 times.
✓ Branch 1 taken 302436 times.
352842 for(int32_t i(0); i < 6; ++i)
11268 {
11269
2/2
✓ Branch 0 taken 137944 times.
✓ Branch 1 taken 164492 times.
302436 if(m.layermap[i] == 0) continue;
11270
11271 137944 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
11272
11273
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 137944 times.
137944 if(layer_screen_index >= TheMaps.size())
11274 continue;
11275
11276 137944 bool trans = m.layeropacity[i] == 128;
11277
11278 //draw valid layers
11279 137944 draw_mapscr(b, TheMaps[ layer_screen_index ], x1, y1, trans);
11280 137944 }
11281
11282
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50406 times.
50406 if(rotation != 0) // rotate
11283 {
11284 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
11285 script_drawing_commands.ReleaseSubBitmap(b);
11286 }
11287 50406 }
11288
11289
11290 1173 void do_bmpdrawlayerr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11291 {
11292 //sdci[1]=layer
11293 //sdci[2]=map
11294 //sdci[3]=screen
11295 //sdci[4]=layer
11296 //sdci[5]=x
11297 //sdci[6]=y
11298 //sdci[7]=rotation
11299 //[8] noclip
11300 //sdci[9]=opacity
11301 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
11302
11303 1173 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
11304
1/2
✓ Branch 0 taken 1173 times.
✗ Branch 1 not taken.
1173 if ( refbmp == NULL ) return;
11305
11306 1173 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11307 1173 int32_t screen = sdci[3]/10000;
11308 1173 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
11309 1173 int32_t x = sdci[5]/10000;
11310 1173 int32_t y = sdci[6]/10000;
11311 1173 int32_t rotation = sdci[7]/10000;
11312
11313 1173 byte noclip = 0;//(sdci[8]!=0);
11314 1173 int32_t opacity = sdci[8]/10000;
11315 1173 uint32_t index = (uint32_t)map_screen_index(map, screen);
11316 1173 const mapscr* m = getmapscreen(map, screen, sourceLayer);
11317
11318
2/2
✓ Branch 0 taken 1167 times.
✓ Branch 1 taken 6 times.
1173 if(!m) //no need to log it.
11319 6 return;
11320
11321
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1167 times.
1167 if(index >= TheMaps.size())
11322 {
11323 Z_scripterrlog("DrawLayer: invalid map index \"%i\". Map count is %d.\n", index, TheMaps.size());
11324 return;
11325 }
11326
11327 1167 const mapscr & l = *m;
11328
11329 1167 BITMAP* b = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
11330
1/2
✓ Branch 0 taken 1167 times.
✗ Branch 1 not taken.
1167 if ( refbmp == NULL ) return;
11331
2/4
✓ Branch 0 taken 1167 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1167 times.
✗ Branch 3 not taken.
1167 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
11332
1/2
✓ Branch 0 taken 1167 times.
✗ Branch 1 not taken.
1167 if(rotation != 0)
11333 b = script_drawing_commands.AquireSubBitmap(256, 176);
11334
11335
11336 1167 const int32_t maxX = isOffScreen ? 512 : 256;
11337
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1167 times.
1167 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
11338 1167 bool transparent = opacity <= 128;
11339
11340
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1167 times.
1167 if(rotation != 0) // rotate
11341 {
11342 draw_mapscr(b, l, x, y, transparent);
11343
11344 rotate_sprite(refbmp, b, x, y, degrees_to_fixed(rotation));
11345 script_drawing_commands.ReleaseSubBitmap(b);
11346 }
11347 else
11348 {
11349
2/2
✓ Branch 0 taken 205392 times.
✓ Branch 1 taken 1167 times.
206559 for(int32_t i(0); i < 176; ++i)
11350 {
11351 205392 const int32_t x2 = ((i&15)<<4) + x;
11352 205392 const int32_t y2 = (i&0xF0) + y;
11353
11354 //if(noclip&&(x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY)) //in clipping rect
11355 {
11356 205392 auto& c = GET_DRAWING_COMBO(l.data[i]);
11357 205392 const int32_t tile = combo_tile(c, x2, y2);
11358
11359
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 205392 times.
205392 if(opacity < 128)
11360 overtiletranslucent16(refbmp, tile, x2, y2, l.cset[i], c.flip, opacity);
11361 else
11362 205392 overtile16(refbmp, tile, x2, y2, l.cset[i], c.flip);
11363
11364 //putcombo( b, xx, yy, l.data[i], l.cset[i] );
11365 }
11366 205392 }
11367 }
11368
11369 //putscr
11370 1173 }
11371
11372
11373
11374 1092 void do_bmpdrawscreenr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11375 {
11376 //sdci[1]=layer
11377 //sdci[2]=map
11378 //sdci[3]=screen
11379 //sdci[4]=x
11380 //sdci[5]=y
11381 //sdci[6]=rotation
11382 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
11383
11384 1092 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
11385
1/2
✓ Branch 0 taken 1092 times.
✗ Branch 1 not taken.
1092 if ( refbmp == NULL ) return;
11386
11387
2/4
✓ Branch 0 taken 1092 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1092 times.
1092 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
11388
11389 1092 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11390 1092 int32_t screen = sdci[3]/10000;
11391 1092 int32_t x = sdci[4]/10000;
11392 1092 int32_t y = sdci[5]/10000;
11393 1092 int32_t x1 = x + xoffset;
11394 1092 int32_t y1 = y + yoffset;
11395 1092 int32_t rotation = sdci[6]/10000;
11396
11397 1092 uint32_t index = (uint32_t)map_screen_index(map, screen);
11398
11399
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1092 times.
1092 if(index >= TheMaps.size())
11400 {
11401 al_trace("DrawScreen: invalid map or screen index. \n");
11402 return;
11403 }
11404
11405 1092 const mapscr & m = TheMaps[index];
11406
11407
11408 1092 BITMAP* b = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
11409
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1092 times.
1092 if ( refbmp == NULL ) return;
11410
11411
1/2
✓ Branch 0 taken 1092 times.
✗ Branch 1 not taken.
1092 if(rotation != 0)
11412 b = script_drawing_commands.AquireSubBitmap(256, 176);
11413
11414 //draw layer 0
11415 1092 draw_mapscr(b, m, x1, y1, false);
11416
11417
2/2
✓ Branch 0 taken 1092 times.
✓ Branch 1 taken 6552 times.
7644 for(int32_t i(0); i < 6; ++i)
11418 {
11419
2/2
✓ Branch 0 taken 2118 times.
✓ Branch 1 taken 4434 times.
6552 if(m.layermap[i] == 0) continue;
11420
11421 2118 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
11422
11423
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2118 times.
2118 if(layer_screen_index >= TheMaps.size())
11424 continue;
11425
11426 2118 bool trans = m.layeropacity[i] == 128;
11427
11428 //draw valid layers
11429 2118 draw_mapscr(b, TheMaps[ layer_screen_index ], x1, y1, trans);
11430 2118 }
11431
11432
1/2
✓ Branch 0 taken 1092 times.
✗ Branch 1 not taken.
1092 if(rotation != 0) // rotate
11433 {
11434 rotate_sprite(refbmp, b, x1, y1, degrees_to_fixed(rotation));
11435 script_drawing_commands.ReleaseSubBitmap(b);
11436 }
11437 1092 }
11438
11439 void do_bmpdrawlayersolidmaskr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11440 {
11441 //sdci[1]=layer
11442 //sdci[2]=map
11443 //sdci[3]=screen
11444 //sdci[4]=layer
11445 //sdci[5]=x
11446 //sdci[6]=y
11447 //sdci[7]=rotation
11448 //sdci[8]=bool noclip
11449 //sdci[9] == opacity
11450
11451 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11452 int32_t screen = sdci[3]/10000;
11453 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
11454 int32_t x = sdci[5]/10000;
11455 int32_t y = sdci[6]/10000;
11456 int32_t x1 = x + xoffset;
11457 int32_t y1 = y + yoffset;
11458 int32_t rotation = sdci[7]/10000;
11459 byte noclip = (sdci[8]!=0);
11460 int32_t opacity = sdci[9]/10000;
11461
11462 uint32_t index = (uint32_t)map_screen_index(map, screen);
11463 const mapscr* m = getmapscreen(map, screen, sourceLayer);
11464
11465 if(!m) //no need to log it.
11466 return;
11467
11468 if(index >= TheMaps.size())
11469 {
11470 al_trace("DrawLayer: invalid map index \"%i\". Map count is %lu.\n", index, TheMaps.size());
11471 return;
11472 }
11473
11474 const mapscr & l = *m;
11475
11476 BITMAP* b = bmp;
11477
11478 if(rotation != 0)
11479 b = script_drawing_commands.AquireSubBitmap(256, 176);
11480
11481
11482 const int32_t maxX = isOffScreen ? 512 : 256;
11483 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
11484 bool transparent = opacity <= 128;
11485
11486 if(rotation != 0) // rotate
11487 {
11488 draw_map_solid(b, l, x1, y1);
11489
11490 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
11491 script_drawing_commands.ReleaseSubBitmap(b);
11492 }
11493 else
11494 {
11495 BITMAP* square = create_bitmap_ex(8,16,16);
11496 BITMAP* subsquare = create_bitmap_ex(8,16,16);
11497 clear_to_color(subsquare,1);
11498 for(int32_t i(0); i < 176; ++i)
11499 {
11500 const int32_t x2 = ((i&15)<<4) + x1;
11501 const int32_t y2 = (i&0xF0) + y1;
11502
11503 if(noclip&&(x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY)) //in clipping rect
11504 {
11505 int32_t sol = (combobuf[l.data[i]].walk);
11506
11507 if ( sol & 1 )
11508 {
11509 blit(subsquare, square, 0, 0, 0, 0, 8, 8);
11510 }
11511 if ( sol & 2 )
11512 {
11513 blit(subsquare, square, 0, 0, 0, 8, 8, 8);
11514 }
11515 if ( sol & 4 )
11516 {
11517 blit(subsquare, square, 0, 0, 8, 0, 8, 8);
11518 }
11519 if ( sol &8 ) {
11520 blit(subsquare, square, 0, 0, 8, 8, 8, 8);
11521 }
11522
11523 blit(square, b, 0, 0, x2, y2, square->w, square->h);
11524 }
11525 }
11526 destroy_bitmap(square);
11527 destroy_bitmap(subsquare);
11528 }
11529
11530 //putscr
11531 }
11532
11533 void do_bmpdrawlayersolidityr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11534 {
11535 //sdci[1]=layer
11536 //sdci[2]=map
11537 //sdci[3]=screen
11538 //sdci[4]=layer
11539 //sdci[5]=x
11540 //sdci[6]=y
11541 //sdci[7]=rotation
11542 //[8] noclip
11543 //sdci[9]=opacity
11544
11545
11546 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11547 int32_t screen = sdci[3]/10000;
11548 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
11549 int32_t x = sdci[5]/10000;
11550 int32_t y = sdci[6]/10000;
11551 int32_t x1 = x + xoffset;
11552 int32_t y1 = y + yoffset;
11553 int32_t rotation = sdci[7]/10000;
11554 byte noclip = (sdci[8]!=0);
11555 int32_t opacity = sdci[9]/10000;
11556
11557 uint32_t index = (uint32_t)map_screen_index(map, screen);
11558 const mapscr* m = getmapscreen(map, screen, sourceLayer);
11559
11560 if(!m) //no need to log it.
11561 return;
11562
11563 if(index >= TheMaps.size())
11564 {
11565 al_trace("DrawLayer: invalid map index \"%i\". Map count is %lu.\n", index, TheMaps.size());
11566 return;
11567 }
11568
11569 const mapscr & l = *m;
11570
11571 BITMAP* b = bmp;
11572
11573 if(rotation != 0)
11574 b = script_drawing_commands.AquireSubBitmap(256, 176);
11575
11576
11577 const int32_t maxX = isOffScreen ? 512 : 256;
11578 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
11579 bool transparent = opacity <= 128;
11580
11581 if(rotation != 0) // rotate
11582 {
11583 draw_map_solidity(b, l, x1, y1);
11584
11585 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
11586 script_drawing_commands.ReleaseSubBitmap(b);
11587 }
11588 else
11589 {
11590 BITMAP* square = create_bitmap_ex(8,16,16);
11591 for(int32_t i(0); i < 176; ++i)
11592 {
11593 const int32_t x2 = ((i&15)<<4) + x1;
11594 const int32_t y2 = (i&0xF0) + y1;
11595
11596 if(noclip && (x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY)) //in clipping rect
11597 {
11598 clear_to_color(square,(combobuf[l.data[i]].walk&15));
11599 blit(square, b, 0, 0, x2, y2, square->w, square->h);
11600 }
11601 }
11602 destroy_bitmap(square);
11603 }
11604
11605 //putscr
11606 }
11607
11608 void do_bmpdrawlayercflagr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11609 {
11610 //sdci[1]=layer
11611 //sdci[2]=map
11612 //sdci[3]=screen
11613 //sdci[4]=layer
11614 //sdci[5]=x
11615 //sdci[6]=y
11616 //sdci[7]=rotation
11617 //[8] noclip
11618 //sdci[9]=opacity
11619
11620
11621 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11622 int32_t screen = sdci[3]/10000;
11623 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
11624 int32_t x = sdci[5]/10000;
11625 int32_t y = sdci[6]/10000;
11626 int32_t x1 = x + xoffset;
11627 int32_t y1 = y + yoffset;
11628 int32_t rotation = sdci[7]/10000;
11629
11630 byte noclip = (sdci[8]!=0);
11631 int32_t opacity = sdci[9]/10000;
11632
11633 uint32_t index = (uint32_t)map_screen_index(map, screen);
11634 const mapscr* m = getmapscreen(map, screen, sourceLayer);
11635
11636 if(!m) //no need to log it.
11637 return;
11638
11639 if(index >= TheMaps.size())
11640 {
11641 al_trace("DrawLayer: invalid map index \"%i\". Map count is %lu.\n", index, TheMaps.size());
11642 return;
11643 }
11644
11645 const mapscr & l = *m;
11646
11647 BITMAP* b = bmp;
11648
11649 if(rotation != 0)
11650 b = script_drawing_commands.AquireSubBitmap(256, 176);
11651
11652
11653 const int32_t maxX = isOffScreen ? 512 : 256;
11654 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
11655 bool transparent = opacity <= 128;
11656
11657 if(rotation != 0) // rotate
11658 {
11659 draw_map_cflag(b, l, x1, y1);
11660
11661 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
11662 script_drawing_commands.ReleaseSubBitmap(b);
11663 }
11664 else
11665 {
11666 BITMAP* square = create_bitmap_ex(8,16,16);
11667 for(int32_t i(0); i < 176; ++i)
11668 {
11669 const int32_t x2 = ((i&15)<<4) + x1;
11670 const int32_t y2 = (i&0xF0) + y1;
11671
11672 if(noclip&&(x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY)) //in clipping rect
11673 {
11674 clear_to_color(square,l.sflag[i]);
11675 blit(square, b, 0, 0, x2, y2, square->w, square->h);
11676 }
11677 }
11678 destroy_bitmap(square);
11679 }
11680
11681 //putscr
11682 }
11683
11684 void do_bmpdrawlayerctyper(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11685 {
11686 //sdci[1]=layer
11687 //sdci[2]=map
11688 //sdci[3]=screen
11689 //sdci[4]=layer
11690 //sdci[5]=x
11691 //sdci[6]=y
11692 //sdci[7]=rotation
11693 //[8] noclip
11694 //sdci[9]=opacity
11695
11696 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11697 int32_t screen = sdci[3]/10000;
11698 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
11699 int32_t x = sdci[5]/10000;
11700 int32_t y = sdci[6]/10000;
11701 int32_t x1 = x + xoffset;
11702 int32_t y1 = y + yoffset;
11703 int32_t rotation = sdci[7]/10000;
11704
11705 byte noclip = (sdci[8]!=0);
11706 int32_t opacity = sdci[9]/10000;
11707 uint32_t index = (uint32_t)map_screen_index(map, screen);
11708 const mapscr* m = getmapscreen(map, screen, sourceLayer);
11709
11710 if(!m) //no need to log it.
11711 return;
11712
11713 if(index >= TheMaps.size())
11714 {
11715 al_trace("DrawLayer: invalid map index \"%i\". Map count is %lu.\n", index, TheMaps.size());
11716 return;
11717 }
11718
11719 const mapscr & l = *m;
11720
11721 BITMAP* b = bmp;
11722
11723 if(rotation != 0)
11724 b = script_drawing_commands.AquireSubBitmap(256, 176);
11725
11726
11727 const int32_t maxX = isOffScreen ? 512 : 256;
11728 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
11729 bool transparent = opacity <= 128;
11730
11731 if(rotation != 0) // rotate
11732 {
11733 draw_map_combotype(b, l, x1, y1);
11734
11735 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
11736 script_drawing_commands.ReleaseSubBitmap(b);
11737 }
11738 else
11739 {
11740 BITMAP* square = create_bitmap_ex(8,16,16);
11741 for(int32_t i(0); i < 176; ++i)
11742 {
11743 const int32_t x2 = ((i&15)<<4) + x1;
11744 const int32_t y2 = (i&0xF0) + y1;
11745
11746 if(noclip&&(x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY)) //in clipping rect
11747 {
11748 clear_to_color(square,(combobuf[l.data[i]].type));
11749 blit(square, b, 0, 0, x2, y2, square->w, square->h);
11750 }
11751 }
11752 destroy_bitmap(square);
11753 }
11754
11755 //putscr
11756 }
11757
11758 void do_bmpdrawlayerciflagr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11759 {
11760 //sdci[1]=layer
11761 //sdci[2]=map
11762 //sdci[3]=screen
11763 //sdci[4]=layer
11764 //sdci[5]=x
11765 //sdci[6]=y
11766 //sdci[7]=rotation
11767 //[8] noclip
11768 //sdci[9]=opacity
11769
11770 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11771 int32_t screen = sdci[3]/10000;
11772 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
11773 int32_t x = sdci[5]/10000;
11774 int32_t y = sdci[6]/10000;
11775 int32_t x1 = x + xoffset;
11776 int32_t y1 = y + yoffset;
11777 int32_t rotation = sdci[7]/10000;
11778 byte noclip = (sdci[8]!=0);
11779 int32_t opacity = sdci[9]/10000;
11780
11781 uint32_t index = (uint32_t)map_screen_index(map, screen);
11782 const mapscr* m = getmapscreen(map, screen, sourceLayer);
11783
11784 if(!m) //no need to log it.
11785 return;
11786
11787 if(index >= TheMaps.size())
11788 {
11789 al_trace("DrawLayer: invalid map index \"%i\". Map count is %lu.\n", index, TheMaps.size());
11790 return;
11791 }
11792
11793 const mapscr & l = *m;
11794
11795 BITMAP* b = bmp;
11796
11797 if(rotation != 0)
11798 b = script_drawing_commands.AquireSubBitmap(256, 176);
11799
11800
11801 const int32_t maxX = isOffScreen ? 512 : 256;
11802 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
11803 bool transparent = opacity <= 128;
11804
11805 if(rotation != 0) // rotate
11806 {
11807 draw_map_comboiflag(b, l, x1, y1);
11808
11809 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
11810 script_drawing_commands.ReleaseSubBitmap(b);
11811 }
11812 else
11813 {
11814 BITMAP* square = create_bitmap_ex(8,16,16);
11815 for(int32_t i(0); i < 176; ++i)
11816 {
11817 const int32_t x2 = ((i&15)<<4) + x1;
11818 const int32_t y2 = (i&0xF0) + y1;
11819
11820 if(noclip&&(x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY)) //in clipping rect
11821 {
11822 clear_to_color(square,(combobuf[l.data[i]].flag));
11823 blit(square, b, 0, 0, x2, y2, square->w, square->h);
11824 }
11825 }
11826 destroy_bitmap(square);
11827 }
11828
11829 //putscr
11830 }
11831
11832
11833
11834 /////////////////////////////////////////////////////////
11835 // do primitives
11836 ////////////////////////////////////////////////////////
11837
11838 // Draw commands can vary in terms of the origin/coordinate system to draw as. This
11839 // is controlled via `DrawOrigin`. Previous to `DrawOrigin`, this always drew
11840 // relative to the playing field (except for offscreen bitmaps).
11841 401197363 void do_primitives(BITMAP *targetBitmap, int32_t type)
11842 {
11843 401197363 do_primitives(targetBitmap, type, 0, playing_field_offset);
11844 401197363 }
11845 402394955 void do_primitives(BITMAP *targetBitmap, int32_t type, int32_t xoff, int32_t yoff)
11846 {
11847 402394955 color_map = &trans_table2;
11848
11849
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 402394955 times.
402394955 if(type > 7)
11850 return;
11851
3/4
✓ Branch 0 taken 127978611 times.
✓ Branch 1 taken 274416344 times.
✓ Branch 2 taken 127978611 times.
✗ Branch 3 not taken.
402394955 if(type >= 0 && origin_scr->hidescriptlayers & (1<<type))
11852 return; //Script draws hidden for this layer
11853
2/2
✓ Branch 0 taken 3366447 times.
✓ Branch 1 taken 399028508 times.
402394955 if(!script_drawing_commands.is_dirty(type))
11854 399028508 return; //No draws to this layer
11855 //--script_drawing_commands[][] reference--
11856 //[][0]: type
11857 //[][1-16]: defined by type
11858 //...
11859 //[][DRAWCMD_BMP_TARGET]: bitmap pointer
11860 //[][DRAWCMD_CURRENT_TARGET]: current render target at time command is queued? unused?
11861
11862 3366447 const int32_t type_mul_10000 = type * 10000;
11863 3366447 const int32_t numDrawCommandsToProcess = script_drawing_commands.Count();
11864 3366447 FFCore.numscriptdraws = numDrawCommandsToProcess;
11865
11866
2/2
✓ Branch 0 taken 300088415 times.
✓ Branch 1 taken 3366447 times.
303454862 for (int i = 0; i < numDrawCommandsToProcess; i++)
11867 {
11868 300088415 auto& command = script_drawing_commands[i];
11869 300088415 int32_t *sdci = &script_drawing_commands[i][0];
11870
11871
2/2
✓ Branch 0 taken 199747925 times.
✓ Branch 1 taken 100340490 times.
300088415 if (sdci[1] != type_mul_10000)
11872 199747925 continue;
11873
11874 100340490 DrawOrigin draw_origin = command.draw_origin;
11875
11876 // get the correct render target, if set via Screen->SetRenderTarget
11877 // Note: This is a deprecated feature.
11878 100340490 BITMAP *bmp = zscriptDrawingRenderTarget->GetTargetBitmap(sdci[DRAWCMD_CURRENT_TARGET]);
11879 bool isTargetOffScreenBmp;
11880
11881
2/2
✓ Branch 0 taken 6431899 times.
✓ Branch 1 taken 93908591 times.
100340490 if(!bmp)
11882 {
11883 93908591 bmp = targetBitmap;
11884 93908591 isTargetOffScreenBmp = false;
11885 93908591 }
11886 else
11887 {
11888 // Render target was set to a internal bitmap (but not the screen bitmap).
11889 6431899 isTargetOffScreenBmp = true;
11890 6431899 draw_origin = DrawOrigin::Screen;
11891 }
11892
11893 int xoffset, yoffset;
11894
1/2
✓ Branch 0 taken 100340490 times.
✗ Branch 1 not taken.
100340490 if (auto r = get_draw_origin_offset(draw_origin, command.draw_origin_target, xoff, yoff))
11895 {
11896 100340490 std::tie(xoffset, yoffset) = *r;
11897 100340490 }
11898 else
11899 {
11900 continue;
11901 }
11902
11903 100340490 secondary_draw_origin_xoff = 0;
11904 100340490 secondary_draw_origin_yoff = 0;
11905
2/2
✓ Branch 0 taken 100340130 times.
✓ Branch 1 taken 360 times.
100340490 if (command.secondary_draw_origin != DrawOrigin::Default)
11906 {
11907
1/2
✓ Branch 0 taken 360 times.
✗ Branch 1 not taken.
360 if (auto r = get_draw_origin_offset(command.secondary_draw_origin, command.secondary_draw_origin_target, xoff, yoff))
11908 {
11909 360 std::tie(secondary_draw_origin_xoff, secondary_draw_origin_yoff) = *r;
11910 360 }
11911 else
11912 {
11913 continue;
11914 }
11915 360 }
11916
11917
40/88
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 2487966 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1160036 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1850 times.
✓ Branch 7 taken 2351475 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 404879 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 1546047 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 2712759 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 5290540 times.
✓ Branch 19 taken 22452549 times.
✓ Branch 20 taken 963845 times.
✓ Branch 21 taken 161253 times.
✓ Branch 22 taken 1587964 times.
✓ Branch 23 taken 163717 times.
✓ Branch 24 taken 9266 times.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✓ Branch 28 taken 1080 times.
✓ Branch 29 taken 933060 times.
✗ Branch 30 not taken.
✓ Branch 31 taken 4336960 times.
✓ Branch 32 taken 50406 times.
✓ Branch 33 taken 7971 times.
✗ Branch 34 not taken.
✓ Branch 35 taken 148823 times.
✗ Branch 36 not taken.
✓ Branch 37 taken 502 times.
✓ Branch 38 taken 144 times.
✗ Branch 39 not taken.
✓ Branch 40 taken 80910 times.
✓ Branch 41 taken 59816 times.
✗ Branch 42 not taken.
✓ Branch 43 taken 824 times.
✗ Branch 44 not taken.
✓ Branch 45 taken 168443 times.
✓ Branch 46 taken 32636464 times.
✗ Branch 47 not taken.
✗ Branch 48 not taken.
✓ Branch 49 taken 865 times.
✓ Branch 50 taken 45504 times.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 53 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✗ Branch 56 not taken.
✓ Branch 57 taken 1173 times.
✓ Branch 58 taken 1092 times.
✗ Branch 59 not taken.
✗ Branch 60 not taken.
✓ Branch 61 taken 1024 times.
✗ Branch 62 not taken.
✗ Branch 63 not taken.
✓ Branch 64 taken 265509 times.
✗ Branch 65 not taken.
✓ Branch 66 taken 113329 times.
✗ Branch 67 not taken.
✗ Branch 68 not taken.
✗ Branch 69 not taken.
✗ Branch 70 not taken.
✗ Branch 71 not taken.
✗ Branch 72 not taken.
✓ Branch 73 taken 325125 times.
✓ Branch 74 taken 2790 times.
✓ Branch 75 taken 34653 times.
✗ Branch 76 not taken.
✗ Branch 77 not taken.
✗ Branch 78 not taken.
✗ Branch 79 not taken.
✗ Branch 80 not taken.
✓ Branch 81 taken 19821648 times.
✗ Branch 82 not taken.
✓ Branch 83 taken 7323 times.
✗ Branch 84 not taken.
✓ Branch 85 taken 906 times.
✗ Branch 86 not taken.
✗ Branch 87 not taken.
100340490 switch(sdci[0])
11918 {
11919 case RECTR:
11920 {
11921 2487966 do_rectr(bmp, sdci, xoffset, yoffset);
11922 }
11923 2487966 break;
11924 case FRAMER:
11925 {
11926 do_framer(bmp, sdci, xoffset, yoffset);
11927 }
11928 break;
11929
11930
11931 case CIRCLER:
11932 {
11933 1160036 do_circler(bmp, sdci, xoffset, yoffset);
11934 }
11935 1160036 break;
11936
11937 case ARCR:
11938 {
11939 do_arcr(bmp, sdci, xoffset, yoffset);
11940 }
11941 break;
11942
11943 case ELLIPSER:
11944 {
11945 1850 do_ellipser(bmp, sdci, xoffset, yoffset);
11946 }
11947 1850 break;
11948
11949 case LINER:
11950 {
11951 2351475 do_liner(bmp, sdci, xoffset, yoffset);
11952 }
11953 2351475 break;
11954
11955 case SPLINER:
11956 {
11957 do_spliner(bmp, sdci, xoffset, yoffset);
11958 }
11959 break;
11960
11961 case PUTPIXELR:
11962 {
11963 404879 do_putpixelr(bmp, sdci, xoffset, yoffset);
11964 }
11965 404879 break;
11966 case PIXELARRAYR:
11967 {
11968 do_putpixelsr(bmp, i, sdci, xoffset, yoffset);
11969 }
11970 break;
11971
11972 case TILEARRAYR:
11973 {
11974 do_fasttilesr(bmp, i, sdci, xoffset, yoffset);
11975 }
11976 break;
11977
11978 case LINESARRAY:
11979 {
11980 do_linesr(bmp, i, sdci, xoffset, yoffset);
11981 }
11982 break;
11983
11984 case COMBOARRAYR:
11985 {
11986 do_fastcombosr(bmp, i, sdci, xoffset, yoffset);
11987 }
11988 break;
11989
11990
11991
11992 case DRAWTILER:
11993 {
11994 1546047 do_drawtiler(bmp, sdci, xoffset, yoffset);
11995 }
11996 1546047 break;
11997
11998 case DRAWTILECLOAKEDR:
11999 {
12000 do_drawtilecloakedr(bmp, sdci, xoffset, yoffset);
12001 }
12002 break;
12003
12004 case DRAWCOMBOR:
12005 {
12006 2712759 do_drawcombor(bmp, sdci, xoffset, yoffset);
12007 }
12008 2712759 break;
12009
12010 case DRAWCOMBOCLOAKEDR:
12011 {
12012 do_drawcombocloakedr(bmp, sdci, xoffset, yoffset);
12013 }
12014 break;
12015
12016 case FASTTILER:
12017 {
12018 5290540 do_fasttiler(bmp, sdci, xoffset, yoffset);
12019 }
12020 5290540 break;
12021
12022 case FASTCOMBOR:
12023 {
12024 22452549 do_fastcombor(bmp, sdci, xoffset, yoffset);
12025 }
12026 22452549 break;
12027
12028 case DRAWCHARR:
12029 {
12030 963845 do_drawcharr(bmp, sdci, xoffset, yoffset);
12031 }
12032 963845 break;
12033
12034 case DRAWINTR:
12035 {
12036 161253 do_drawintr(bmp, sdci, xoffset, yoffset);
12037 }
12038 161253 break;
12039
12040 case DRAWSTRINGR:
12041 {
12042 1587964 do_drawstringr(bmp, i, sdci, xoffset, yoffset);
12043 }
12044 1587964 break;
12045
12046 case DRAWSTRINGR2:
12047 {
12048 163717 do_drawstringr2(bmp, i, sdci, xoffset, yoffset);
12049 }
12050 163717 break;
12051
12052 case QUADR:
12053 {
12054 9266 do_drawquadr(bmp, sdci, xoffset, yoffset);
12055 }
12056 9266 break;
12057
12058 case QUAD3DR:
12059 {
12060 do_drawquad3dr(bmp, i, sdci, xoffset, yoffset);
12061 }
12062 break;
12063
12064 case TRIANGLER:
12065 {
12066 do_drawtriangler(bmp, sdci, xoffset, yoffset);
12067 }
12068 break;
12069
12070 case TRIANGLE3DR:
12071 {
12072 do_drawtriangle3dr(bmp, i, sdci, xoffset, yoffset);
12073 }
12074 break;
12075
12076 case POLYGONR:
12077 {
12078 1080 do_polygonr(bmp, i, sdci, xoffset, yoffset);
12079 }
12080 1080 break;
12081
12082
12083 case BITMAPR:
12084 {
12085 933060 do_drawbitmapr(bmp, sdci, xoffset, yoffset);
12086 }
12087 933060 break;
12088
12089 case BITMAPEXR:
12090 {
12091 do_drawbitmapexr(bmp, sdci, xoffset, yoffset);
12092 }
12093 break;
12094
12095 case DRAWLAYERR:
12096 {
12097 4336960 do_drawlayerr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp);
12098 }
12099 4336960 break;
12100
12101 case DRAWSCREENR:
12102 {
12103 50406 do_drawscreenr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp);
12104 }
12105 50406 break;
12106
12107 7971 case BMPRECTR: bmp_do_rectr(bmp, sdci, xoffset, yoffset); break;
12108 case BMPFRAMER: bmp_do_framer(bmp, sdci, xoffset, yoffset); break;
12109 148823 case BMPCIRCLER: bmp_do_circler(bmp, sdci, xoffset, yoffset); break;
12110 case BMPARCR: bmp_do_arcr(bmp, sdci, xoffset, yoffset); break;
12111 502 case BMPELLIPSER: bmp_do_ellipser(bmp, sdci, xoffset, yoffset); break;
12112 144 case BMPLINER: bmp_do_liner(bmp, sdci, xoffset, yoffset); break;
12113 case BMPSPLINER: bmp_do_spliner(bmp, sdci, xoffset, yoffset); break;
12114 80910 case BMPPUTPIXELR: bmp_do_putpixelr(bmp, sdci, xoffset, yoffset); break;
12115 59816 case BMPDRAWTILER: bmp_do_drawtiler(bmp, sdci, xoffset, yoffset); break;
12116 case BMPDRAWTILECLOAKEDR: bmp_do_drawtilecloakedr(bmp, sdci, xoffset, yoffset); break;
12117 824 case BMPDRAWCOMBOR: bmp_do_drawcombor(bmp, sdci, xoffset, yoffset); break;
12118 case BMPDRAWCOMBOCLOAKEDR: bmp_do_drawcombocloakedr(bmp, sdci, xoffset, yoffset); break;
12119 168443 case BMPFASTTILER: bmp_do_fasttiler(bmp, sdci, xoffset, yoffset); break;
12120 32636464 case BMPFASTCOMBOR: bmp_do_fastcombor(bmp, sdci, xoffset, yoffset); break;
12121 case BMPDRAWCHARR: bmp_do_drawcharr(bmp, sdci, xoffset, yoffset); break;
12122 case BMPDRAWINTR: bmp_do_drawintr(bmp, sdci, xoffset, yoffset); break;
12123 865 case BMPDRAWSTRINGR: bmp_do_drawstringr(bmp, i, sdci, xoffset, yoffset); break;
12124 45504 case BMPDRAWSTRINGR2: bmp_do_drawstringr2(bmp, i, sdci, xoffset, yoffset); break;
12125 case BMPQUADR: bmp_do_drawquadr(bmp, sdci, xoffset, yoffset); break;
12126 case BMPQUAD3DR: bmp_do_drawquad3dr(bmp, i, sdci, xoffset, yoffset); break;
12127
12128 case BITMAPGETPIXEL: bmp_do_getpixelr(bmp, sdci, xoffset, yoffset); break;
12129 case BMPTRIANGLER: bmp_do_drawtriangler(bmp, sdci, xoffset, yoffset); break;
12130 case BMPTRIANGLE3DR: bmp_do_drawtriangle3dr(bmp, i, sdci, xoffset, yoffset); break;
12131 case BMPPOLYGONR: bmp_do_polygonr(bmp, i, sdci, xoffset, yoffset); break;
12132 1173 case BMPDRAWLAYERR: do_bmpdrawlayerr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12133 1092 case BMPDRAWSCREENR: do_bmpdrawscreenr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12134 case BMPDRAWSCREENSOLIDR: do_bmpdrawscreen_solidmaskr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12135 case BMPDRAWSCREENSOLID2R: do_bmpdrawscreen_solidr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12136 1024 case BMPDRAWSCREENCOMBOFR: do_bmpdrawscreen_cflagr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12137 case BMPDRAWSCREENCOMBOIR: do_bmpdrawscreen_ciflagr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12138 case BMPDRAWSCREENCOMBOTR: do_bmpdrawscreen_ctyper(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12139 265509 case BMPBLIT: bmp_do_drawbitmapexr(bmp, sdci, xoffset, yoffset); break;
12140 case BMPMODE7: bmp_do_mode7r(bmp, sdci, xoffset, yoffset); break;
12141 113329 case BMPBLITTO: bmp_do_blittor(bmp, sdci, xoffset, yoffset); break;
12142 case TILEBLIT: do_tileblit(bmp, sdci, xoffset, yoffset, false, "TileBlit()"); break;
12143 case COMBOBLIT: do_comboblit(bmp, sdci, xoffset, yoffset, false); break;
12144 case BMPTILEBLIT: do_tileblit(bmp, sdci, xoffset, yoffset, true, "TileBlit()"); break;
12145 case BMPCOMBOBLIT: do_comboblit(bmp, sdci, xoffset, yoffset, true); break;
12146 case READBITMAP: bmp_do_readr(bmp, i, sdci, xoffset, yoffset); break;
12147 case WRITEBITMAP: bmp_do_writer(bmp, i, sdci, xoffset, yoffset); break;
12148 325125 case CLEARBITMAP: bmp_do_clearr(bmp, sdci, xoffset, yoffset); break;
12149 2790 case BITMAPCLEARTOCOLOR: bmp_do_clearcolorr(bmp, sdci, xoffset, yoffset); break;
12150 34653 case REGENERATEBITMAP: bmp_do_regenr(bmp, sdci, xoffset, yoffset); break;
12151
12152 case BMPDRAWLAYERSOLIDR: do_bmpdrawlayersolidmaskr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12153 case BMPDRAWLAYERCFLAGR: do_bmpdrawlayercflagr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12154 case BMPDRAWLAYERCTYPER: do_bmpdrawlayerctyper(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12155 case BMPDRAWLAYERCIFLAGR: do_bmpdrawlayerciflagr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12156 case BMPDRAWLAYERSOLIDITYR: do_bmpdrawlayersolidityr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12157 19821648 case BMPWRITETILE: do_bmpwritetile(bmp, sdci, xoffset, yoffset); break;
12158 case BMPDITHER: do_bmpdither(bmp, sdci, xoffset, yoffset); break;
12159 7323 case BMPREPLCOLOR: do_bmpreplcol(bmp, sdci, xoffset, yoffset); break;
12160 case BMPSHIFTCOLOR: do_bmpshiftcol(bmp, sdci, xoffset, yoffset); break;
12161 906 case BMPMASKDRAW: do_bmpmaskdraw(bmp, sdci, xoffset, yoffset); break;
12162 case BMPMASKBLIT: do_bmpmaskblit(bmp, sdci, xoffset, yoffset); break;
12163
12164 // The following are special cases, in that the target bitmap is fixed (darkscr_bmp).
12165
12166 case DRAWLIGHT_CONE:
12167 {
12168 int32_t cx = sdci[2]/10000 + xoffset;
12169 int32_t cy = sdci[3]/10000 + yoffset;
12170 int32_t dir = sdci[4]/10000;
12171 int32_t length = sdci[5];
12172 int32_t transp_rad = sdci[6];
12173 int32_t dith_rad = sdci[7];
12174 int32_t dith_type = sdci[8];
12175 int32_t dith_arg = sdci[9];
12176
12177 if(length >= 0) length /= 10000;
12178 else length = game->get_light_rad()*2;
12179 if(!length) break;
12180 if(dir < 0) break;
12181 else dir = NORMAL_DIR(dir);
12182 if(transp_rad >= 0) transp_rad /= 10000;
12183 if(dith_rad >= 0) dith_rad /= 10000;
12184 if(dith_type >= 0) dith_type /= 10000;
12185 if(dith_arg >= 0) dith_arg /= 10000;
12186
12187 // Undo the inherit offset applied within the function. xoffset/yoffset handles for us here.
12188 cx += viewport.x;
12189 cy += viewport.y;
12190
12191 doDarkroomCone(cx,cy,length,dir,darkscr_bmp,nullptr,dith_rad,transp_rad,dith_type,dith_arg);
12192 }
12193 break;
12194
12195 case DRAWLIGHT_CIRCLE:
12196 case DRAWLIGHT_SQUARE:
12197 {
12198 int32_t cx = sdci[2]/10000 + xoffset;
12199 int32_t cy = sdci[3]/10000 + yoffset;
12200 int32_t radius = sdci[4];
12201 int32_t transp_rad = sdci[5];
12202 int32_t dith_rad = sdci[6];
12203 int32_t dith_type = sdci[7];
12204 int32_t dith_arg = sdci[8];
12205
12206 if(radius >= 0) radius /= 10000;
12207 else radius = game->get_light_rad();
12208 if(!radius) break;
12209 if(transp_rad >= 0) transp_rad /= 10000;
12210 if(dith_rad >= 0) dith_rad /= 10000;
12211 if(dith_type >= 0) dith_type /= 10000;
12212 if(dith_arg >= 0) dith_arg /= 10000;
12213
12214 // Undo the inherit offset applied within the function. xoffset/yoffset handles for us here.
12215 cx += viewport.x;
12216 cy += viewport.y;
12217
12218 if (sdci[0] == DRAWLIGHT_CIRCLE)
12219 doDarkroomCircle(cx,cy,radius,darkscr_bmp,nullptr,dith_rad,transp_rad,dith_type,dith_arg);
12220 else
12221 doDarkroomSquare(cx,cy,radius,darkscr_bmp,nullptr,dith_rad,transp_rad,dith_type,dith_arg);
12222 }
12223 break;
12224 }
12225 100340490 }
12226
12227
12228 3366447 color_map=&trans_table;
12229 402394955 }
12230
12231 16225781 void CScriptDrawingCommands::Clear()
12232 {
12233 16225781 scb.update();
12234 16225781 dirty_layers.clear();
12235
2/2
✓ Branch 0 taken 11501377 times.
✓ Branch 1 taken 4724404 times.
16225781 if(commands.empty())
12236 11501377 return;
12237
12238 //only clear what was used.
12239 4724404 memset((void*)&commands[0], 0, count * sizeof(CScriptDrawingCommandVars));
12240 4724404 count = 0;
12241
12242 4724404 draw_container.Clear();
12243 16225781 }
12244 CScriptDrawingCommands* CScriptDrawingCommands::pop_commands()
12245 {
12246 CScriptDrawingCommands* ret = new CScriptDrawingCommands();
12247 if(commands.empty())
12248 return ret;
12249 ret->push_commands(this, false);
12250
12251 memset((void*)&commands[0], 0, count * sizeof(CScriptDrawingCommandVars));
12252 count = 0;
12253
12254 draw_container.Clear();
12255 return ret;
12256 }
12257 void CScriptDrawingCommands::push_commands(CScriptDrawingCommands* other, bool del)
12258 {
12259 commands.insert(commands.end(), other->commands.begin(), other->commands.end());
12260 count += other->count;
12261 if(del) delete other;
12262 }
12263
12264 149699 void do_script_draws(BITMAP *targetBitmap, mapscr* scr, int32_t xoff, int32_t yoff, bool hideLayer7)
12265 {
12266
2/2
✓ Branch 0 taken 148705 times.
✓ Branch 1 taken 994 times.
149699 if(XOR(scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG)) do_primitives(targetBitmap, 2, xoff, yoff);
12267
2/2
✓ Branch 0 taken 147881 times.
✓ Branch 1 taken 1818 times.
149699 if(XOR(scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG)) do_primitives(targetBitmap, 3, xoff, yoff);
12268 149699 do_primitives(targetBitmap, 0, xoff, yoff);
12269 149699 do_primitives(targetBitmap, 1, xoff, yoff);
12270
2/2
✓ Branch 0 taken 994 times.
✓ Branch 1 taken 148705 times.
149699 if(!XOR(scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG)) do_primitives(targetBitmap, 2, xoff, yoff);
12271
2/2
✓ Branch 0 taken 1818 times.
✓ Branch 1 taken 147881 times.
149699 if(!XOR(scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG)) do_primitives(targetBitmap, 3, xoff, yoff);
12272 149699 do_primitives(targetBitmap, 4, xoff, yoff);
12273 149699 do_primitives(targetBitmap, 5, xoff, yoff);
12274 149699 do_primitives(targetBitmap, 6, xoff, yoff);
12275
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 149699 times.
149699 if(!hideLayer7) do_primitives(targetBitmap, 7, xoff, yoff);
12276 149699 }
12277